How to edit host and port?

By default, Nuxt development server host is localhost (only accessible from within the host machine).

Host 0.0.0.0 is designated to tell Nuxt to resolve a host address, which is accessible to connections outside of the host machine (e.g. LAN).

You can configure the connection variables in different ways. They are listed from highest to lowest priority.

Note: If port is assigned the string value of '0' (not 0, which is falsy), a random port will be assigned to your Nuxt application.

As direct arguments

  1. nuxt --hostname myhost --port 3333

Or

  1. "scripts": {
  2. "dev": "nuxt --hostname myhost --port 3333"
  3. }

Configure in nuxt.config.js:

Inside your nuxt.config.js:

  1. export default {
  2. server: {
  3. port: 8000, // default: 3000
  4. host: '0.0.0.0' // default: localhost
  5. }
  6. // other configs
  7. }

With NUXT_HOST and NUXT_PORT env variables

Similar to HOST and PORT but more specific in case you need those for something else.

  1. "scripts": {
  2. "dev": "NUXT_HOST=0.0.0.0 NUXT_PORT=3333 nuxt"
  3. }

With HOST and PORT env variables

  1. "scripts": {
  2. "dev": "HOST=0.0.0.0 PORT=3333 nuxt"
  3. }

Via a nuxt config in the package.json:

Inside your package.json:

  1. "config": {
  2. "nuxt": {
  3. "host": "0.0.0.0",
  4. "port": "3333"
  5. }
  6. },
  7. "scripts": {
  8. "dev": "nuxt"
  9. }