How to Deploy Your Angular App on Heroku

Thats great you created your angular app and ready to deploy, here is the steps to make your app deployed and running on Heroku.

I hope you have made the build of your app using below command-

ng build  –prod

1. check your server.js and it should be look as below scripts:

const express = require(‘express’);
const http = require(‘http’)
const path = require(‘path’);

const app = express();

app.use(express.static(path.join(__dirname, ‘dist’)));

app.get(‘*’, (req, res) => {
res.sendFile(path.join(__dirname + ‘/dist/index.html’));

const port = process.env.PORT || 3000;
app.set(‘port’, port);

const server = http.createServer(app);
server.listen(port, () => console.log(‘running’));

2. Now in your solution check the package.json file. In your package.json, move @angular/cli and @angular/compiler-cli from devDependencies to dependencies and save it.

3. finally also make the changes in your package.json, add postinstall: ng build –prod and start: node server.js to scripts to proceed. Here once you make the changes, please save all and we are good here.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *