A short tutorial on how to deploy an Angular application on Heroku using Node and Express framework. This project was generated with Angular CLI version 7.3.0.
This project has following prerequisites which needs to be installed on your system in order to proceed.
- Open terminal into the folder where you want to setup the project.
- Run:
ng new <name-of-project>
without <>
cd
into the project folder and create a new fileserver.js
- Run
npm install express
in terminal. - Paste the following code into the server.js file
- Open package.json and make sure its build, start, postinstall script and dependencies section looks similar to this.
- Commit all the changes and push it to a newly created repository.
- Open Heroku
- Create a new app.
- Select Github as your deployment method.
- Enable Automatic Deploys.
- Select master branch of your created repository for deployment and wait for it to build the project.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.