NodeJS By Examples

PM2

Start Node app with pm2 :

$ pm2 start bin/www -i 0 -n 'crawler'

-i 0  the number of instances is equal to number of processors

-n 'crawler'  the name of pm2 process will be crawler

 

Option -i is still experimental and can cause problems, so use just:

$ pm2 start bin/www -n 'crawler'

 

After that:

$pm2 restart 'crawler'

$pm2 stop 'crawler'

$pm2 delete 'crawler'

 

To list all PM" processes:

$pm2 list

┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ crawler  │ 0  │ fork │ 6250 │ online │ 0       │ 0s     │ 10.301 MB   │ disabled │

 

 

 

To kill all process started with PM2 on port 3333 use:

$ fuser -n tcp -k 3333