13_How to Deploy NodeJs app on Ubuntu in Production
地址:https://www.codewithharry.com/blogpost/deploy-nodejs-app-on-ubuntu/
How to deploy a Node.js application in production
In this post, we will see how to run and deploy NodeJS apps in production. Follow the steps below:
Step 1 - Install Nodejs
Let's download nodejs from Nodesource. NodeSource is a company which provides enterprise-grade Node support and maintains a repository containing the latest versions of Node.js.
Let's install nodejs now:
Check the installation of node and npm using the following commands:
You will see the versions of nodejs and npm
Step 2 - Creating a sample nodejs file
Let's create a sample app and paste some basic code into it.
Paste the following code inside it:
Lets now install express so that we can run this app server:
run the application
You should now be able to see the hello world page when you visit http://server-ip:3000
Step 3 - Using pm2 as a process manager
Let's install and use pm2 as a process manager. Install pm2 using the commands below:
Start the application using the following command:
Step 4 - Configuring Nginx as a reverse proxy
Now let's configure Nginx as a reverse proxy. This will help us get the security features from Nginx. Also, we can serve static content using Nginx.
Let's install Nginx using the following command:
Let's create a conf file for our Nodejs app using the command below
Copy the following content to this file
Activate this configuration using the command below:
Visit http://your-ip/ and your application should work fine. Happy coding!