How to deploy angular 2 app on heroku

Deployment of Angular 2 Application on Heroku is very simple task. We can deploy Angular 2 app on Heroku by many ways like Heroku CLI and Github.

Before deployement process we need to sure that our application should be in a production deployment mode.

Suppose we have created the dist folder for production deployment. If still you have not created the dist or deployment folder the we can create it by following cammands.

If you are using webpack then ng build --prod is the command for create the build files or dist folder. We need to deploy only these build files to run our angular app with any backend server like express, hapi and other web servers.

If your application structure is like below format after create the build files or dist folder.


To deploy the angular 2 application we need a web server like express js.

So we need to install a express js framework to deploy the angular app.

Create a package.json and server.js file to with express js framework.


	const express = require('express'); 
	const app = express(); 
	const path = require('path');  

	app.use(express.static(__dirname + '/dist'));  
	app.listen(process.env.PORT || 8080);  
	app.get('/*', function(req, res){   
		res.sendFile(path.join(__dirname + '/dist/index.html')); 

	console.log('Server listening'); 

Now upload all these files on Github or use Heroku CLI to deploy directly. Here we will use git to upload all the files on github


Then we can deploy our angular app with heroku. We need Heroku account and need to create our app with Heroku.

Test a Node RESTful API with M …

Test a Node RESTful API with Mocha and Chai. I still remember the satisfaction of being finally able to write the backend part of a bigger app in node and I am sure many of you do it too. And then? We need to make sure our app behaves the way we expe …

read more

How To Set Up a Node.js Applic …

How To Set Up a Node.js Application for Production on Ubuntu 20.04 . Node.js is an open-source JavaScript runtime environment for building server-side and networking applications. The platform runs on Linux, macOS, FreeBSD, and Windows. Though you ca …

read more