How to setup a private NPM repository with Sinopia



This tutorial shows you how to setup a private NPM repository server with Sinopia in 4 easy steps.

setup a private NPM repository with Sinopia
sinopia on NPM

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 sinopia.
  • Open a shell in this folder and type
  • 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:

Note that the server is running and you should be able to access it at http://localhost:4873.
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
  • 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:

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:

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:

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:

You need to issue this command from within the root folder of the package you want to publish.

When you first issue this command you might get an unauthorized error.
In that case you need to login to the Sinopia server with this command:

Specify the username and password as generated during the Sinopia installation or use another Sinopia username/password.
Now retry the publish command.

 

Wrap up

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.

Advantages:

  • You have a private npm repository.
  • You have a in-house cache of used packages.

Disadvantages:

  • You need to maintain a server.
  • You need to run the npm set registry command on each client.

See Also: