简体   繁体   中英

How to start Node.js service automatically on CENTOS 6.7?

I have two servers running nodejs applications. I did some setting with the first one before. After that setting, when I start the command line, if I run node command, I see the service is running.

But I do not remember what I did. So in my second server, anytime I restart command line session, when I type node I get -bash: node: command not found .

Could anyone remind me please?

NOTE: Please don't tell me this is duplicate. Search for keywords "start, node service, automatically, etc." most of them tell about the use of 'forever'. I know forever (gdi), mine is a lot more stupid question and I don't know the correct terminology just yet.

I would suggest using pm2 or forever

For pm2 do the following Install it using

npm install pm2 -g

-g installs it globally. Then do following

pm2 start app.js --name="api" 

Once that is done, you can do pm2 list to view all running services as follows

pm2列表

Make pm2 start at boot time

pm2 startup

This will automatically start your node.js app.

Works for my 4 apps that are in production.

Hope this helps.

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