3

I tried the old solution but it not works any more, then I tried to read the nuxt 3 documentation, and it is not actually update.

So how to change How to change Nuxt 3 Port without change dev script like @kissu did here

I tried the old solution

on /.nuxt.config.ts

export default defineNuxtConfig(
  
    server: {
      port: 8080,
    },
  
})

and I got http://localhost:3000

Edit:

I found the way using .env file

into your .env file ([project_root] /.env)

PORT=8080

Nuxt 3 detect it automaticaly from your env variable .

3 Answers3

3

In Nuxt3 nuxt.config.ts

export default defineNuxtConfig({
  devServer: {
    port: 8000
  }
})
Michal S
  • 1,104
  • 17
  • 26
1

In Nuxt3 to change default PORT

for Development Environment , in package.json

 "dev": "nuxt dev -p 3020",

for Production Environment, create .env file in root folder ( if not exist )

PORT=3200

This will work when you run command

npm run preview
Chirag Joshi
  • 409
  • 1
  • 4
  • 13
0

to change production port after npm run build

and run NITRO_PORT=4000 node .output/server/index.mjs

Listening http://[::]:4000

or using pm2 ecosystem.config.js

module.exports = {
  apps: [
    {
      name: 'NuxtAppName',
      port: '3000',
      exec_mode: 'cluster',
      instances: 'max',
      script: './.output/server/index.mjs'
    }
  ]
}
Tung Dmctv
  • 1
  • 1
  • 2