27 Nov 2016
Deploy a Node Website with Express and Heroku
Download Node and NPM: https://nodejs.org/en/
For Linux users,
Create a package.json file that includes our project dependencies.
Express is the web framework. You can declare other tools such as jade and/or ejs templating engines. Server.js
- Requires Express as our main framework to build the Node application.
- The localhost port is set to 5000 for testing locally.
- The static file public folder location is where our main web files such as index.html, css and image files will live.
The server will render the index file as our home page. To test the Node application, open the command prompt, navigate to the project folder root and type in:
You should get the message:
Test in a browser by navigating to localhost:5000
Now that we have a website running on the local machine, we’ll use Heroku to send it live. Heroku is a cloud platform service that supports several programming languages. Once deployed, the website URL will look like this: `generated-app-name.herokuapp.com`
Go to Heroku Dev Center: https://devcenter.heroku.com/
- Setup a free account
- Download Heroku Toolbelt (Package for using the command line)
Open Git Bash and clone the working project to your local GitHub folder:
Navigate to the project’s root in GitHub:
Create a new file called, Procfile, which tells Heroku what command should be executed to start the app. Include the following:
Prepare Heroku to receive the source code by entering:
Heroku will generate a random name for the app that can be changed later.
Deploy the code:
Open the website by entering:
Or by navigating to the app’s url, generated-app-name.herokuapp.com.
Our site is now live on the Heroku platform and we can easily edit and monitor changes using Git.