Deploying Node.js application in Heroku and some tips

This article is about deploying a nodejs application in Heroku.
If you do not have any node.js application simply copy this code in app.js file.

console.log("Again at " + new Date());
setTimeout(again, 1000);
};
again();

The main application file is app.js.

Now, Create a file named Procfile in your main directory with following context
          
                web: node app.js

It would tell heroku to start a process named web with this command.

Download and install the heroku toolkit for your O.S. from here: Heroku Toolkit

If your node.js project is not git versioned, then do

          git init
          git add .
          git commit -m "Added to git"

After installing heroku toolkit, open a command terminal, and go to your node.js directory. Now, execute following commands:

           heroku create

This would give your website some name.

If you want to set the configurations to production type:

            heroku config:set NODE_ENV=production

Now, just push to the heroku using

          git push heroku master

master is your local branch. heroku would point to the heroku website repository.

Lastly, do

      heroku open
This would open a browser with your sample website.


Some tips:
1. If you are using mongodb, you can use mongolab or mongohq.
   
        heroku addons:add mongolab

You would need to go through online procedure of giving some debit/credit card information to get an instance of mongodb.

2. For debugging to see the logs that your application printed using console, you can do:

      heroku logs --source app

3. If you are using websockets, you should do:

     heroku labs:enable websockets
 

To see a sample application see : Chatpod

Comments