如何更改 Nuxt 3 端口

Jes*_*lho 8 port typescript server nuxt.js .env

我尝试了旧的解决方案,但它不再起作用,然后我尝试阅读 nuxt 3 文档,但它实际上并未更新。

那么如何更改How to Change Nuxt 3 Port而不更改开发脚本,就像@kissu在这里所做的那样

我尝试了旧的解决方案

在 /.nuxt.config.ts 上

export default defineNuxtConfig(
  
    server: {
      port: 8080,
    },
  
})
Run Code Online (Sandbox Code Playgroud)

我得到了 http://localhost:3000

编辑:

我找到了使用 .env 文件的方法

进入您的 .env 文件([project_root] /.env)

PORT=8080
Run Code Online (Sandbox Code Playgroud)

Nuxt 3 会自动从您的环境变量中检测到它。

Mic*_*l S 9

在 Nuxt3 中nuxt.config.ts

export default defineNuxtConfig({
  devServer: {
    port: 8000
  }
})
Run Code Online (Sandbox Code Playgroud)


Tun*_*ctv 7

之后更改生产端口npm run build

并运行NITRO_PORT=4000 node .output/server/index.mjs

正在收听 http://[::]:4000

或使用 pm2 Ecosystem.config.js

module.exports = {
  apps: [
    {
      name: 'NuxtAppName',
      port: '3000',
      exec_mode: 'cluster',
      instances: 'max',
      script: './.output/server/index.mjs'
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)