Deploy Angular App On Heroku

1/ Install node modules

npm install @angular/cli@latest @angular/compiler-cli --save-dev
npm install express -s

2/ Update angular.json

"outputPath": "dist"

3/ Add server.js to root

//Install express server
const express = require('express');
const path = require('path');

const app = express();

// Serve only the static files form the dist directory
app.use(express.static(__dirname + '/dist'));

app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname + '/dist/index.html'));
});

// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);

4/ Update package.json

add to root

	"engines": {
		"node": "14.x",
		"npm": "6.x"
	  }

add under “scripts”

	"heroku-postbuild": "ng build --prod"
	"start": "node server.js"

5/ Deploy on Heroku

  • create a new app connected to your Github
  • manual deploy: choose your branch to deploy

2 thoughts on “Deploy Angular App On Heroku”

  1. ERROR: initial exceeded maximum budget. Budget xxx kB was not met by xxx MB with a total of xxx MB

    RESOLVE:
    – Open angular.json file and find budgets keyword
    – change ‘maximumWarning’ like this
    “budgets”: [
    {
    “type”: “initial”,
    “maximumWarning”: “2mb”,
    “maximumError”: “5mb”
    }
    ]

    Like

  2. ERROR: big integer literals are not available in the configured target environment

    RESOLVE:
    change ‘target’ in tsconfig.json
    “target”: “es2020”,

    Like

Leave a comment