< back

Publishing npm modules from TravisCI

Travi CI can publish your modules in NPM's public or private registry. This is a much better option than doing it from your local machine. I do it with some of my open source projects,  this way I don't have to worry about distributing the latest version of a library after updating the code.


NOTE: Travis has updated the process to deploy NPM modules, it's much easier now using their CLI. Follow the instructions in their website.

Travis has this process documented in their website, but I find some steps are not quite clear. Hopefully this instructions will make it more understandable.

First thing you need is a npm account with publish permissions in the public npm registry (or your organisation's private one). Once your credentials are set you need to add them to .npmrc, the npm configuration file in your home directory with npm adduser:

$ npm adduser
Username: mserranom
Email: (this IS public) mserranom@gmail.com

Assuming your project already has a configured .travis.yml descriptor (follow this guide otherwise) you need to include an encrypted version of the npm authentication key in order to allow Travis to publish the module on your behalf:

$ cat ~/.npmrc

Use Travis CLI to update the .travis.yml descriptor. You'll be prompted to introduce the value of _authToken:

$ cd project_repo # folder containing .travis.yml
$ travis encrypt --add deploy.api_key
Reading from stdin, press Ctrl+D when done

In order to execute the encrypt command you have to be in the folder where .travis.yml is located. Once you introduce your authentication key, press Ctrl+D, don't enter spaces or new lines. The .travis.yml descriptor should be updated with the new public key.

language: node_js
sudo: false
- '0.12'
  provider: npm
  skip_cleanup: true
  email: mserranom@gmail.com
    secure: FX+e8xv+oiKfaX7V6aIoD04sy3SsTpDGtc ...

Push your code and check the new build, it should finish with a deployment stage and the new version of the package should appear shortly afterwards in npmjs.org.


comments powered by Disqus