Deploy Angular 5 + Nodejs Express app to Heroku
Here's how I make my Angular app to deploy and work on Heroku:
- Your
server.js
should look something like this: https://hastebin.com/zavehahide.js - In your
package.json
, move@angular/cli
and@angular/compiler-cli
fromdevDependencies
todependencies
- Also in your
package.json
, addpostinstall: ng build --prod
andstart: node server.js
toscripts
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.