NPM (npmjs) is the package manager for Nodejs. By default, npm modules are deployed and retrieved over the Internet from the public package registry maintained on http://npmjs.org. A private npm registry can be used to upload your own packages as well as third-party packages. Hosting a private NPM registry for your own is very helpful when you would like to share the code only among members in your team (but not entire the world). You can develop and maintain all your private projects and their reused modules as private node packages.
Sinopia is a private/caching NPM registry server that you can setup with zero configuration.
Install and Configure Sinopia
Using npm to install Sinopia as global nodejs component in your server:
$ sudo npm install -g sinopia
You can change the Sinopia settings in ~/.config/sinopia/config.yaml file. Starting Sinopia as following:
$ sinopia
By default, Sinopia server is listening on the port 4873. Your should configure your npm to use this port:
$ npm set registry http://localhost:4873/
Now, each time you install a new package, npm will ask Sinopia (through registry localhost:4873) instead of default registry for retrieving and installing the package. For example:
$ sudo npm install -g hexo-cli
This package (hexo-cli) and all dependent packages are retrieved as the following:
The last, if you want to switch to default registry, you can use this command:
$ npm set registry https://registry.npmjs.org/
Running Sinopia as a daemon
Thanks to Fabrizio Ruggeri’s Script, you can make Sinopia server run as a daemon.
Other solutions
Repository managers with support for private npm registries:
- Sonatype Nexus: From version 2.10, Sonatype Nexus supports private npm registries.
- Artifactory: From version 3.2, Artifactory fully supports npm repositories.