Setting up Heroku to host your website
This Guide is based on the official heroku guide.
-
Create Heroku Account.
-
Install Heroku Toolbelt:
wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
-
Log in to heroku:
heroku login #Enter your Heroku credentials...
-
Preparing the app:
Assuming you have a fully functional web application already, here are the steps to prepare it for heroku.
If you don’t, simply run:
git clone https://github.com/heroku/node-js-getting-started.git cd node-js-getting-started
Otherwise, follow the instructions below.
-
You need a local package.json file to define your application’s dependencies.
If you have been using a global one, simply copy it over to your application’s directory.
cd ${APP_DIRECTORY} cp ${HOME}/package.json .
You can also run:
npm init --yes
-
Then, you must define a Procfile :
If your main app starts with server.js,
web: node server.js
If no Procfile is defined, the app will default to the start script in your package.json:
"start": "node server.js"
If there is no start script, then the default is server.js.
-
In your application, make sure it listens to a port Heroku supplies:
var port = process.env.PORT || 8000; server.listen(port);
-
-
Deploying the app:
-
Create the app on heroku:
heroku create
-
Deploy the code:
git push heroku master
-
-
Ensure that the app instance is running:
heroku ps:scale web=1
-
Check that the app is running with:
heroku open
-
[Tip] if you need to configure environmental variables:
heroku config:set VAR1_NAME=VAR1_VALUE VAR2_NAME=VAR2_VALUE
Running Heroku Locally
If you have to test new features that aren’t yet stable, you wouldn’t want to experiment in your running instance.
That is what local instances are for.
bash
heroku local