We need an express server to make the Angular app live.
Install express and path.
npm install express path
Create server.js
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(__dirname + '/dist/<FOLDER_NAME>'));
app.get('/*', (req,res,next) => {
res.sendFile(path.join(__dirname + '/dist/dictionary/index.html'));
});
app.listen(process.env.PORT || 8000);
Add these lines in package.json
inside scripts
"start": "node server.js",
"heroku-postbuild": "ng build --prod"
Add engines inside package.json
"engines": {
"node": "14.15.3",
"npm": "6.14.9"
},
Add this project to GitHub and connect this repository with your Heroku app.
Click on deploy.
Thanks for reading :)
Discussion (4)
Great, thanks! Just one small correction if I may: "res.sendFile(path.join(dirname + '/dist/dictionary/index.html'));" should probably be changed to something like "res.sendFile(path.join(dirname + '/dist//index.html'));".
You can make it like this too:
I was able to deploy my angular app following this post.I would like to further clerify.here Folder_Name is name of folder in your dist folder (this folder will be created while you build locally).While writing engines write the versions of node and npm installed locally on your system.(find it using node --version and npm --version).
Thanks for this post!