Deploy your first app

At this point, you should have an app that works locally on your computer. The following steps outline updates you need to make in order to deploy the codes.

Update package.json

In this step, we need to add some code to the package.json file so that we can run the app from a remote server.

Right now, there is a good chance that the file will look like this:

  1. {
  2. "name": "application-name",
  3. "version": "0.0.1",
  4. "private": true,
  5. "scripts": {
  6. "start": "node ./bin/www"
  7. },
  8. "dependencies": {
  9. "express": "~4.0.0",
  10. "static-favicon": "~1.0.0",
  11. "morgan": "~1.0.0",
  12. "cookie-parser": "~1.0.1",
  13. "body-parser": "~1.0.0",
  14. "debug": "~0.7.4",
  15. "jade": "~1.3.0"
  16. }
  17. }

At the end of the dependencies": { ... } object, you need to add a comma , so that we can add more code. First let’s add the main keyword:

  1. "main": "app.js",

Notice the trailing comma? This is because we are going to add more stuff. After that, add in the engines object and the specific engines we need to run this app:

  1. "engines": {
  2. "node": "0.10.26",
  3. "npm": "1.4.3"
  4. }

You should have something that looks like the following:

  1. {
  2. "name": "application-name",
  3. "version": "0.0.1",
  4. "private": true,
  5. "scripts": {
  6. "start": "node ./bin/www"
  7. },
  8. "dependencies": {
  9. "express": "~4.0.0",
  10. "static-favicon": "~1.0.0",
  11. "morgan": "~1.0.0",
  12. "cookie-parser": "~1.0.1",
  13. "body-parser": "~1.0.0",
  14. "debug": "~0.7.4",
  15. "jade": "~1.3.0"
  16. },
  17. "main": "app.js",
  18. "engines": {
  19. "node": "0.10.26",
  20. "npm": "1.4.3"
  21. }
  22. }

Don’t forget the Grunt + Bower

If at this time you do not have any of the Grunt packages or Bower in the dependenciess object, we need to get that in there.

You can either add them manually to the package.json file or dun:

  1. $ npm install --save grunt
  2. $ npm install --save grunt-sass
  3. $ npm install --save bower

Something that you probably don’t have is the ability for the deployed server to run the Grunt tasks. For this we need Grunt-CLI.

  1. $ npm install --save grunt-cli

Right about now, you should be looking pretty good.

Postinstall instructions

When we deploy the codes to Heroku, we have to tell it to run some commands, basically install the Bower packages and run the Grunt tasks. To do this, we need to add the instructions within the scripts object of the package.json file.

Directly under the "start": "node ./bin/www", add:

  1. "postinstall": "./node_modules/.bin/bower install && ./node_modules/.bin/grunt"

There, now we have everything that Heroku needs to install the packages and run the scripts.

Add the Procfile

This is a file that Heroku needs in order to start the app.

  1. $ touch Procfile

Add the following code:

  1. web: npm start

Heroku will use this to kick start the app.

Make this a Git repo

It is important to make this a git repo BEFORE you create the Heroku server. WAIT! Before you go all crazy on the Git, there are some things we need to do.

You should have a .gitignore file in your repo at this point. open that up and make sure you are ignoring all the node_modules, all the bower_components and anything in the /stylesheets/*.css spectrum.

  1. node_modules
  2. public/stylesheets/*.css
  3. bower_components

Great. Now you can git init your repo.

  1. $ git add .
  2. $ git commit -m "initial commit"

It is not required at this time to make this a Github repo, but you may want to do this if you make this a real app.

Deploy the codes

This is pretty hard here. Make sure to follow the commands specifically:

  1. $ heroku create <your-app-name>
  2. $ git push heroku master

Rejoice

If all is well, you should see a return like this:

  1. http://<your-new-app>.herokuapp.com/ deployed to Heroku

Go to that URL and REJOICE!!!!!