This post will cover the step needed to take the angular universal app to the production server.
This post assumes that you have running angular universal application and which is generated by angular CLI.
Now open your terminal or command prompt, point the cursor to the project folder and run the build command as shown below.
It will create a dist folder along with composed project files and which we will need to place on the server. Additionally, for some of the module dependencies, we also need to place
package.json and run
npm install to install node modules and in most cases, this step is not needed.
And by default Angular App is configured to start on 4000 port, once the above build generation steps complete, move all the files to the server using SCP or FTP client. And start the server with below command. For example, the project is located at /var/www/project/dist/…
Once it is started you should able to access the website with your public IP address at http://public-ip:4000. But if you close the termail or command prompt you will lose the access to the website. To keep the node process alive, we should use something like forever, PM2 modules… etc.
In this post, we gonna use PM2, so let’s install it globally with
npm install pm2 -g . After installation, let’s use PM2 to run the server as shown below.
Now you can access the website with your public IP address at http://public-ip:4000
It is always better to use a proxy for the node app rather than directly exposing the app. Install Nginx, if it is not available already on the server. Now update the Nginx configuration file, in a way Nginx port 80 will proxy to port 4000 in background.
Below are the Nginx configuration details
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.