Pm2: PM2 list doesn't show used port

Created on 23 Apr 2014  路  8Comments  路  Source: Unitech/pm2

PM2 list doesn't show anything in the port column. I'm running my script with -x

Most helpful comment

it would be awesome if it could show the port or have an option to show it

All 8 comments

364 #409 (duplicate)

Okay but these issues aren't helpful either.

it would be awesome if it could show the port or have an option to show it

I don't understand how anyone can use it when you never even know which port to proxy to. However, I've discovered that you can export the port as an environment variable in order to set it yourself.

In order to start an app on port 3000 you could say PORT=3000 pm2 start app.js in Terminal. There's possibly another way to set the port but I haven't tried it myself. That would be to say app.set('port', 3000) in bin/www or whatever file you trigger the start command with.

By default Express applications are set in bin/www like this:

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

I can confirm my site wasn't running on port 3000 by using PM2 without that PORT=3000 statement in Terminal at first, so it seems like this isn't working.

Well pm2 is pretty awesome other than the status not showing the port number being a slight annoyance. I usually look up the pid by running ps aux | grep node then I can see which app matches up to each process

Does ps aux | grep node show you the port PM2 chooses to use or is that for the node command or something?

No sorry you are right ps aux | grep node doesn't show which process is running on which port. In prod I have been using a docker container with just 1 node process on the container, so it hasn't really affected me, until I tried to run a few on the same container

ps aux | grep node will show you all the node processes running and there pid

29994   0.0  2.6  3464468 432048 s000  S+   11:34PM   0:17.29 node server.js

So I can see its name is server.js, and if I need to kill the process I can see the pid e.g. 29994, but that doesn't help if I have a few and they are all node server.js

This is great. Thanks for sharing that! I'll definitely be using it _a lot_ in the future! 馃槃

Was this page helpful?
0 / 5 - 0 ratings