简体   繁体   中英

How to deploy Express NodeJS project to Centos server?

I have never deployed a NodeJS application and therefore don't know how to do it. I have worked and completed a Express NodeJS application that uses MongoDB as its database.

While working on the project, I would usually use "npm start" to test the current progress of the application (by checking it on port 3000).

To run the project, I have bought a virtual private server that runs in Centos. I have my files on the server and have used "npm start" to make sure everything works fine. I usually do this by SSHing into the server and working from there.

Now, how exactly am I supposed to deploy the project such that I can exit the SSH session and the project would still be live on the server IP address.

Thank you for any help!

What you're describing is the need to run the NodeJS process in the background. There are other ways to do this, but in order to manage your application well, I would recommend that you use a NodeJS process manager.

Have a look at PM2 This is a popular solution, the documentation is good, and should work just fine for you.

I would recommend installing it globally on your VPS npm install -g pm2 and then navigate to your project root and run pm2 start whatever-your-main-js-file-is-named.js You can then see information on all processes with the command pm2 list and there are several other commands for understanding more about the processes that you are running, just check out their docs or their pm2 --help

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