Save time managing and deploying your node.js app

Using private npm on Heroku

About the author

nodejitsu nodejitsu

Other popular posts

- Scaling Isomorphic Javascript Code - Keep a node.js server up with Forever - Package.json dependencies done right
- npm cheat sheet - 6 Must Have Node.js Modules
Sign up to our platform for free - get $20 usage

Previously this week we showed how to deploy to the Nodejitsu PaaS using a private npm registry. Not using the Nodejitsu PaaS? No problem: you can also deploy using a private npm registry to Heroku!

If you already have a Heroku app this is simple. If not, why don't you checkout their getting started documentation. First (just like before) we recommend you create a specific deploy user for your private npm registry first. This allows you to separate access control from the personal accounts of the developers on your team.

npm config set https://<your-subdomain>  
npm adduser  
# Enter new credentials for your
# own deployment user.

Ensure you add this user to your private npm account at https://<your-subdomain> and you're ready to go!

Now that we have your private npm deploy user created and added to your registry we just need to add a .npmrc file to the root directory of your application. Follow along below:

1. Backup your existing personal .npmrc file
cp ~/.npmrc ~/.npmrc-local  
2. Login with your deploy user
npm login --registry  
# Enter the credentials for your deploy user
3. Copy your current .npmrc to your Heroku application
cp ~/.npmrc path/to/application  
git add .  
git commit -m 'Add private .npmrc'  
git push heroku master  
4. Restore your personal .npmrc file
mv ~/.npmrc-local ~/.npmrc  

And ... voila!

  • All of your private npm dependencies for your project you will be seamlessly installed for every deployment of your Heroku application.
  • You'll always be able to deploy during public npm downtime since you're now using our bifurcated and dedicated public replica:

If this sounds too easy then we've done our job right! Ready to try it out? Great! You can signup for your private npm registry at Plans start at just $25.