How to deploy angular universal to production

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.

0 0 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Oblitas Kevin
Oblitas Kevin
9 months ago

Hola llegaste a probar con el angular 9?

8 months ago

Hey, did you try to run an angular 9 universal app with pm2? Protection Status
Would love your thoughts, please comment.x