Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a port number for pm2

I'm trying to use pm2 to manage a node.js cluster

pm2 start . -i 3 

I'm currently running the app on heroku and using a Procfile with the above command, but I cannot figure out how to configure pm2 to use the existing PORT env var. Something like pm2 start . -p $PORT

What am I missing?

like image 663
Luke W Avatar asked Jul 19 '15 14:07

Luke W


People also ask

How do I run a pm2 on a specific port?

Inside ecosystem. config. js you specify one entry object for each server instance you want to launch through PM2. The point is that you can also specify environment vars for the different processes and that way you can setup $PORT for all the processes.

Which port does pm2 use?

Starting from PM2 3.2, we changed the networking connection by using a direct Websocket connection to our server on the port 443, so you only need OUTBOUND on port 443 TCP open.

Where does pm2 store config?

The default configuration file is ecosystem. core3. config. js , and is located in the root folder of lisk-service : It contains a configuration to connect to a local Lisk Core node.


1 Answers

You can use environment variable. For example:

  1. NODE_PORT=3002 pm2 start -i 0 app.js

  2. Read value in app:

console.log(process.env.NODE_PORT);

Or, if you are build express app:

  1. PORT=3002 pm2 start -i 0 ./bin/www

  2. Express load PORT automatically at start application.

like image 87
stdob-- Avatar answered Oct 02 '22 12:10

stdob--