简体   繁体   中英

nodejs express app deploying to production

Sorry if this is a basic question, I am still wrapping my head around nodejs deployments. I have an app written on nodejs which I want to deploy to production. So far for testing purposes I have used Express. However from what I know Express is a dev server and not a production server. How do I deploy the nodejs app to production and what is the server I should use. Plus I have a lot of code written for express like routes and middleware, how does this work when I deploy to another server?

When you create your application with express.js, all express modules have been specified in package.json and will be installed as npm modules.

All you need to do is just install node.js on your production servers, put your code there, run npm install , then start the web server with NODE_ENV=production param. It would be a plus if you can use grunt or gulp to process static assets (js / css minification, ...) to optimize the performance for production mode.

For more information, you can take a look here: https://expressjs.com/en/advanced/best-practice-performance.html

You can use pm2 combined with ExpressJs to deploy on remote server. Basically pm2 makes your code run forever in background task with cluster mode.

Basically you need to put your files into remote server and create a .json or yaml file for pm2 to understand what will be the process.

Then you should install libs and modules through npm install . After this you need to install pm2 on your remote server using npm i -g pm2 .

After all of them, you can use pm2's basic cli commands to deploy. pm2 start process.yml --env=production is a basic example for deployment. You can use pm2 stop process.yml for stopping the task. You can also use pm2 monit for system monitoring. If you want to see the logs, you can run pm2 logs . If you want to restart or update: pm2 reload all or pm2 update helps.

For remote server, you can use clouds for best performance. You can look the pricing of AWS , Azure , GCloud , Heroku or DigitalOcean . They are providing free tiers and you can search for them.

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