Reputation: 3206
I have a Node.js website hosted on Heroku, that I deploy with git. I use several node modules, referenced in package.json; is there a way to prevent Heroku to 'refresh' them each time I deploy a new version of the code, as long as package.json did not change?
Note: this would be especially useful for 'native' modules, whose compilation takes a bit of time; for .js-only modules, I was successful removing them from package.json, and adding their node_modules/ folder in the git repo.
Upvotes: 13
Views: 4892
Reputation: 1448
I'm the maintainer of the official Heroku Node.js Buildpack.
We have a new version of the buildpack in beta that features caching support, designed specifically for the use case you described above. You can read more about it at https://github.com/heroku/heroku-buildpack-nodejs/tree/diet#about-this-refactor
Eventually this will become the default Node.js buildpack on Heroku, but if you want to use it now you'll need to set the BUILPACK_URL config var explicitly:
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs#diet -a my-node-app
git commit -am "fakeout" --allow-empty
git push heroku
Upvotes: 8
Reputation: 391
Seems like there has recently been progress by David Dollar at the heroku-buildpack-nodejs.
In short:
heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-nodejs
See answer here: https://stackoverflow.com/a/18535675/1318839
Upvotes: 1
Reputation: 11438
Clone the Heroku node.js buildpack, and modify it to remove the rebuild
command.
The command is currently run here: https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/compile#L180 , but that's bound to change.
You can run create an app that uses your own buildpack by modifying the command below to match your own repo:
heroku create --buildpack http://github.com/heroku/heroku-buildpack-nodejs.git
Or change the buildpack of an existing app with:
heroku config:add BUILDPACK_URL=git://github.com/heroku/heroku-buildpack-nodejs.git
Upvotes: 0
Reputation: 2764
You can add both .js and native npm packages and still avoid the "refresh", (at least the re-downloading part of the "refresh".)
Include the native packages to your node_modules/
directory. When you deploy to Heroku, npm install
will skip the downloading of the package. npm rebuild
is also run. It will take some time to re-compile the native packages, but it should be very bearable unless you have tons of native packages.
Sidenote: Heroku doc on what Heroku does when you push a nodejs app.
Sidenote: The npm rebuild
is needed because there "are mysterious failures that can happen between node and native code modules after a node upgrade".
Upvotes: 0