0

I am currently transferring a Nuxt 2 project over to Nuxt 3. The server I use has a fixed IP address on which the application runs.

In Nuxt 2 there were the following options in nuxt.config.js in which I could assign the appropriate IP address:

servers: {
 host: process.env.NUXT_DAEMON_IP,
 port: '3000' // optional
}

However, in Nuxt 3, this option is no longer supported.

Where and how can I store these options in Nuxt 3? Do I have to do this via the nitro options?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Tobi360
  • 188
  • 1
  • 10

2 Answers2

0

For production, you can specify your env variables as:

NITRO_HOST or HOST
NITRO_PORT or PORT

Documentation: https://nuxt.com/docs/getting-started/deployment#configuring-defaults-at-runtime

For development, you can use the following code in nuxt.config.js:

export default defineNuxtConfig({
  devServer: {
    host: ...,
    port: ...
  },
  // ...
})

Documentation: https://nuxt.com/docs/api/configuration/nuxt-config#devserver

learntheropes
  • 444
  • 3
  • 11
0

In Nuxt 3, you can set the server host and port using the nitro configuration file.

Create a .nitro folder in your project root directory, if it doesn't exist already. In the .nitro folder, create a file named config.yml.

In your config.yml file, add the following lines to specify the desired IP address and port number:

server:
  host: <your-ip-address>
  port: <port-number>

Replace <your-ip-address> with the actual IP address of your server and <port-number> with the port number on which you want to run your application.

After setting these options, start your Nuxt 3 project using the nitro dev command.

Note that nitro provides many other configuration options for your Nuxt 3 project. You can learn more about them by visiting the official nitro documentation.

Thanks.