This tutorial shows you how to setup a private NPM repository server with Sinopia in 4 easy steps.
Sinopia is a private/caching NPM repository server.
It allows you to have a local NPM registry with zero configuration.
1. Installation and Initial Configuration of Sinopia on a server
- Make sure you have nodejs installed on your server.
- On your server create a folder called
- Open a shell in this folder and type
1$ npm install -g sinopia
- From this new directory, start Sinopia to build the initial configuration file.
On initial startup in an empty directory, the output will resemble the following:
Config file doesn't exist, create a new one? (Y/n) Y
Creating a new configuration file: "./config.yaml"
If you want to setup npm to work with this registry,
run following commands:
$ npm set registry http://localhost:4873/
$ npm set always-auth true
$ npm adduser
Note that the server is running and you should be able to access it at
Unless you want to use this Sinopia server only at your local machine, it is a good idea to change the host name and port of the Sinopia server so it can be accessed from other clients in the network:
2. Changing the host name and port of the Sinopia server
In order to change the host name and port of the Sinopia server, you need to modify the
config.yaml file which is located in the root folder of the Sinopia installation.
- Search for
1# listen: localhost:4873
- Uncomment it and change the host name and the port as desired. For example:
3. Configuring npm on the client to use Sinopia
Sinopia is just another npm registry so from the client standpoint, you’ll only need to point to this new registry instead of registry.npmjs.org. To do this, run the following command (replacing localhost:4873 with the host and port running Sinopia) on each client:
$ npm set registry "http://localhost:4873"
At this point you can start installing npm packages on the client through the sinopia server.
If you ever want to undo this action then run this command on the client:
$ npm set registry "http://registry.npmjs.org"
4. Publish packages from a development (client) machine to the Sinopia server.
Before publishing private code, check the
npm config to ensure you will push to the private registry:
$ npm config get registry
shows you the URL to the registry you will push your package to.
After verifying the registry, you can publish your package with the following command:
$ npm publish
You need to issue this command from within the root folder of the package you want to publish.
In that case you need to login to the Sinopia server with this command:
$ npm login
Specify the username and password as generated during the Sinopia installation or use another Sinopia username/password.
Now retry the publish command.
This tutorial showed you haw to setup and use a Sinopia npm registry server.
Using such a server has some advantages and disadvantages, though it will be clear that the advantages outweigh the disadvantages.
- You have a private npm repository.
- You have a in-house cache of used packages.
- You need to maintain a server.
- You need to run the
npm set registrycommand on each client.