Recently at Chiedo Labs, we started working with private npm modules.
Getting things working with our local development environments was trivial.
But getting things working on Heroku was not, so here’s what we learned after a few Google searches.
1. Generating an Authentication Token
First, we needed to generate an authentication token that Heroku could use to gain access to our account’s resources. You can do so by logging into your npm account and clicking on your icon in the top-right hand corner of the webpage and then navigating to the tokens page.
2. Create a New Read-only Token
I chose the read-only option because in theory, there’s no reason Heroku should need to make any changes to our packages. So create your token and be sure to copy the token that’s displayed at the top of the page. It’s only displayed once so make sure you save it somewhere safe.
3. Prepare your Local Development Environment
Add the following to your ~/.profile or ~/.bashrc
Restart your terminal.
4. Prepare your project
Then add a file named .npmrc to the root of the project you’re deploying to Heroku. And in the .npmrc file, add these contents.
5. Add Your Authentication Token To Heroku
In your Heroku app, add an environment variable named NPM_TOKEN and set it equal to the authentication token you got from npm.
6. Deploy Your App To Heroku
Lastly, deploy your app and it’s business as usual. Things should just work. If they don’t, leave a comment below.
Thanks to the following two resources on the npm blog. The first was most of the solution but the auth token solution it recommended seemed unstable for production. The second was the icing on the cake.
We're Hiring‼️ ?? Looking to join our team of web developers? We're passionate about innovation, family, and community. Apply today!