How can I invoke npm on heroku command line (to install bower components)?

Stefan picture Stefan · Feb 6, 2013 · Viewed 21.2k times · Source

Bower is for client side Javascript what npm is for the server side and reads a component.json file to recognize dependencies that should be fetched at deploy time so I'd be happy it heroku would run it at slug compilation time.

Unfortunately I can not invoke npm or bower from a heroku console or one-off command (heroku run "npm help") (heroku run bash -> npm help) as it's possible with ruby's rake. I've put npm and node (latest/x versions) in my package.json but in the engines section, not the dependencies.

I think this could be solved by customizing the node buildpack but I consider this a little too heavy task just for activating something so obvious.

Answer

xavier.seignard picture xavier.seignard · Feb 12, 2013

You can also setup a postintall command, something like this in your package.json

"dependencies": {
    "bower": "0.6.x"
},
"scripts": {
    "postinstall": "./node_modules/bower/bin/bower install"
}

Then npm install will also install bower dependencies.

Pros : one command to rule them all.

Cons : you unnecessarily embed bower as a dependency.