W
W
WebDev2019-01-23 10:20:37
JavaScript
WebDev, 2019-01-23 10:20:37

How to run a nuxt project on a different port?

There is a site on nuxtjs that runs the server on port 3000. For development, I decided to launch another server on port 3001.
To do this, I added the following code to package.json:

...
"scripts": {
    "start_dev": "nuxt start --port 3001",
    ...
}
...

Now if I write npm run start_dev everything works.
Next, I need to demonize this case. I am using pm2. As far as I understand, you cannot run pm2 with parameters via the command line, but you need to create a config file. Created pm2.config.js file
module.exports = {
  apps: [{
    name            : "dev_script",
    script          : "npm",
    watch: false,
    args            : "start_dev",
    cwd             : "./"
  }]
};

I'm trying to run it via pm2 start pm2.script.js, the script starts and then crashes.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Taras Fomin, 2019-01-23
@Tarik02

...
"scripts": {
    "start_dev": "PORT=3001 nuxt start",
    ...
}
...

K
Klein Maximus, 2019-01-23
@kleinmaximus

pm2.json at root

{
  "name": "xxx",
  "script": "server.js",
  "instances": "1",
  "env": {
    "NODE_ENV": "development",
    "PORT": 3000
  },
  "env_production" : {
    "NODE_ENV": "production",
    "PORT": 3001
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question