Deploy Angular 5 + Nodejs Express app to Heroku Deploy Angular 5 + Nodejs Express app to Heroku heroku heroku

Deploy Angular 5 + Nodejs Express app to Heroku


Here's how I make my Angular app to deploy and work on Heroku:

  1. Your server.js should look something like this: https://hastebin.com/zavehahide.js
  2. In your package.json, move @angular/cli and @angular/compiler-cli from devDependencies to dependencies
  3. Also in your package.json, add postinstall: ng build --prod and start: node server.js to scripts

You should be good to go.


Usually when this error happens to me I have problems with node dependencies. Try to remove the node_modules folder, and the dist folder. From there spin everything up again, this mimics how heroku will build your project.


In your server.js you need to redirect your http call to the index.

app.route('/*', function(req,res) {  res.redirect(__dirname + '/dist/index.html')})

In the above it'll redirect any call to your index.html.