Packaging Your Angular App With NodeJS Backend For Production
A step by step Guide With Different Approaches
There are so many ways we can package and ship the Angular app to production. There are serverless and traditional architectures. In traditional architecture, we have different ways: Nodejs, Java, Python, etc.
In this post, we are going to discuss how we can package the Angular app with nodejs backend. Finally, we will deploy this packaged application on AWS Elastic Beanstalk.
- Prerequisites
- Example Project
- Manual Implementation
- With Webpack
- Packaging With Gulp
- With Docker
- Deploying on AWS Elastic Beanstalk
- Summary
- Conclusion
Prerequisites
Let’s see what are all the prerequisites for this. You can actually go through these links if you want to explore these tools on your own.
Server Technology
Angular
Editors
Build/ Task Runners
Container Technology
If you are new to this and want to know how to build an Angular app with Nodejs backend, here is a post for you. You can skip this if you are already familiar with this.
Example Project
This is a simple project which demonstrates developing and running Angular application with NodeJS. We have a simple app in which we can add users, count, and display them at the side, and retrieve them whenever you want.

Here is a Github link to this project. You can clone it and run it on your machine.
// clone the project
https://github.com/bbachi/angular-nodejs-example.git// install and start the project
npm install
npm startManual Implementation
In this manual implementation, we build the Angular app and place the appropriate code into one folder and run or deploy the application. As a first step, we need to build the Angular app and all the static assets and built files are placed into the dist folder.
// change to my-app directory
cd my-app// build the app
npm run buildAll the built and static assets are placed under this folder dist/angular-nodejs-example

Once you built the application, all you need to do is create a separate folder and place the nodejs related stuff in that folder. Let’s create a folder called angular-nodejs and put server.js, package.json, and dist folder inside it.

Run the application
Let's run the app by importing the whole folder angular-nodejs into VSCode editor and install the dependencies for the server.
// install dependencies
npm install// run the app
npm start (node server.js)
The app is running on the server port 8081.

Disadvantages
All the below steps should be done manually and these are time-consuming tasks.
- We have to build Angular code manually
- We have to place all the built files into a separate folder
- We need to install node dependencies before we run the app
With Webpack
In the above implementation, once we put everything in the folder we need to install dependencies for the nodejs server to run the app. This is an additional step we need to do before running the app.
We can skip this step with the webpack. When we build the Angular code, the Angular CLI uses a webpack internally to build and bundle the entire code into few files. We can use the same for the nodejs server as well.
First, we need to install a webpack globally and in the project as well.
// install webpack
npm install webpack -g
npm install webpack --saveWe need to have a webpack.config.js in the root folder since a webpack looks for this file. Here is the file. We have an entry file and output file and it is placed in the root folder.







