Question

how to change default port on pm2 with nuxt 3 project

Hi I want to change the default port 3000 to 3001

according to nuxt doc we just need to add the port to .env file https://nuxt.com/docs/getting-started/deployment#configuring-defaults-at-runtime

I put those to my env but not working

#NITRO_PORT = "3001"
PORT = "3001"

how I build the nuxt 3

first I go to nuxt project directory run npm run build them pm2 start

after I check netstat -plant | grep 3001 does not return anything

but netstat -plant | grep 3000 did has return

0
0 :::3000
:::* LISTEN
711987/PM2 v5.2.2:

btw this is my ecosystem.config.js

module.exports = {
    apps: [
        {
            name: 'nuxt-php-framework',
            exec_mode: 'cluster',
            instances: 'max',
            script: './.output/server/index.mjs'
        }
    ]
}


this is my package .json



{
  "name": "nuxt-php-framework",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "axios": "^1.2.1",
    "nuxt": "^3.0.0"
  },
  "devDependencies": {
    "@nuxt/postcss8": "^1.1.3",
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.20",
    "tailwindcss": "^3.2.4"
  }
}


thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
January 4, 2023
Accepted Answer

Hi @stupidboy,

Add the port in the module.export section and then start your application. Something like the following should do the trick

  1. module.exports = {
  2. apps: [
  3. {
  4. name: 'nuxt-php-framework',
  5. port: 3001,
  6. exec_mode: 'cluster',
  7. instances: 'max',
  8. script: './.output/server/index.mjs'
  9. }
  10. ]
  11. }

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.