Dynamic port & Bower + Grunt scripts with Heroku host

I use Heroku to host some project like Osprey, and I need to admit that this is really a nice platform to host your personal projects for free. It’s really easy to start with but you need to know a few of things…

First of all, check the Node tutorial provided by Heroku.

Bower & Grunt

If you have some bower or grunt scripts to launch after the npm install and before the npm start, you need to add a bash script reference in your package.json file. Your package.json file will contain a postinstall command:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "node server.js",
  "postinstall": "bash ./build.sh"

And your build.sh file should contain all the commands to build the rest of your project (copy, move files, etc…)

./node_modules/bower/bin/bower install

Dynamic port

Heroku assigns dynamically a port to your app. So, if you have set a fixed port in your server.js file, it will not work with the heroku deployment. The port is added to the process.env.PORT variable so you need to pull it from there. You app.listen method should look something like this:

var port = process.env.PORT;
app.listen(port || 3000);

23 Comments Dynamic port & Bower + Grunt scripts with Heroku host

  1. Terese

    It’s genuinely very complex in this full of activity life
    to listen news on TV, so I only use internet for that purpose, and get the hottest information.

  2. Stephany

    I loved as much as you will receive carried out
    right here. The sketch is tasteful, your authored subject matter
    stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following.

    unwell unquestionably come more formerly again as exactly
    the same nearly a lot often inside case you shield this hike.


Leave a Reply

Your email address will not be published.