How to deploy angular 2 app on heroku

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.

 	/e2e 	/dist 	/node_modules 	/src 	.angular-cli 	.editorconfig 	karma.conf.js 	package.json 	protractor.conf.js 	README.md 	tsconfig.json 	tslint.json 

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.

package.json

 {   "name": "express-backend-server-for-angular-app",   "version": "1.0.0",   "description": "Express Backend Deployment Server For Angular App",   "main": "server.js",   "scripts": {     "start": "node server.js"   },   "author": "Anil Kapoor",   "license": "ISC",   "dependencies": {     "express": "^4.16.2"   },   "engines": {     "node": "6.11.1",     "npm": "3.10.10"   } } 

server.js

 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

 	/dist 	package.json 	server.js 

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

Very nice blog. Hats off you guys

Security Checks in Node Js

Security Checks in Node Js

We can use lots of security check on node js for development and production environment. …

read more
What is scope in JavaScript

What is scope in JavaScript

What is scope in JavaScript …

read more