heroku is also simple deployment software
- download the heroku command line interface
- once installed, create a heroku account on heroku.com
- after you've created an account, login on your command line by running
heroku login
add the following to your package.json file:
- this will let Heroku know that you want to create a Node.js environment:
"engines": {
"node": "7.4.0"
}
- you can also add an optional
"heroku-postbuild"
field which will get run afternpm install
. Here you can add things likewebpack
or runseed
files - basically anything you'd want to run beforenpm start
In your server.js
make the following changes:
- change you
app.listen
to includeprocess.env.PORT || 3000
(replace '3000' with whatever your port number is). You need to includeprocess.env.PORT
because Heroku uses this to dynamically assign a port number:
app.listen(process.env.PORT || '9999', () => console.log('Listening on port 9999'));
To create your app on heroku, run the following command (from within your main project repo):
heroku create
if you now go to heroku.com and look at your projects, you should see a newly created project with a weird somewhat random name (you can chane this name on project settings on the heroku website)
- Similarly, change your Sequelize database connection to the following:
let sequelizeConnection = process.env.NODE_ENV === 'production' ? new Sequelize(process.env.DATABASE_URL) : new Sequelize('postgres://natemaddrey@localhost:5432/music-db');
- Then, from the command line run
heroku addons:add heroku-postgresql:hobby-dev
. This will create a new database instance for your deployed app.
- to deploy new code, run
git push heroku master
- then open the URL that heroku gives you in your browser (it can sometimes take up to 30 minutes to go live)