简体   繁体   中英

pm2 not starting properly

I am trying to start a nodejs application in pm2 in bluehost shared hosting.

I am running following command to start the server:

pm2 start ./bin/www

then it shows following message and server is not starting.

[PM2] Spawning PM2 daemon with pm2_home=/home4/[username]/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /home4/[username]/manufacturing/files/bin/www in fork_mode (1 instance)
[PM2] Done.

I tried starting the server using node./bin/www command and it start successfully but when I am using pm2 it is not working.

further when i run pm2 list , it shows nothing

[PM2] Spawning PM2 daemon with pm2_home=/home4/[username]/.pm2
[PM2] PM2 Successfully daemonized
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

UPDATE

[PM2] Spawning PM2 daemon with pm2_home=/home4/pineoran/.pm2
[PM2] PM2 Successfully daemonized
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
Aborted

what should i do??

Your NodeJS application should have a main js file to run. Go to project path and then:

pm2 start server.js

This is what I used. Then in pm2 list , there was my server process running.

You must have superuser privilege when you use port below 1024. In local computer, we mostly have superuser privilege, so you could start your node server with 80 port. But in the server, it depend on your user privilege. If you have superuser privilege in the server, you also can start your node with 80 port. But, if you didn't have it, you only can use port above 1024.

You could simply use node./bin/www to start server to check what kind of error message show up. If error message say you couldn't listen the port, then you should change your port to other, such as 3000, 4000. And then use node./bin/www to start server again. If you successfully start your server with node./bin/www , you also could use pm2 to start server.

Last, when you use pm2 to start node application, you should use complete file name. If your node file is www.js , you shoud use pm2 start www.js instead of pm2 start www . But, if your node file is www , you should use pm2 start www .

More detail about List_of_TCP_and_UDP_port_numbers .
There is a section (Well-known ports) talk about priviliged port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM