Node Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

We will use a tool called sinopia.

We install it with npm:

npm install -g sinopia 

Next, simply start sinopia as a service:

sinopia &> /dev/null & 

Alternatively, this is if we're on Windows:

START /B "" sinopia > nul 2> nul 

In order to publish to our local registry, we'll need to configure npm to point at Sinopia's HTTP endpoint.

We can do so with the following command:

npm set registry http://localhost:4873 
Hosting Sinopia
In order to host Sinopia, either over the public Internet or within cloud infrastructure on in-house metal, several Sinopia settings need to be configured. These settings are typically located at ~/.config/sinopia/config.yaml, although we can pass our own file with sinopia my-config.yaml. In particular, we would want to set an admin password hash, restrict access in the packages field, and listen to host 0.0.0.0. We can find out more about configuration options at https://github.com/rlidwka/sinopia/blob/master/conf/full.yaml. Additionally, there are ready-made Chef, Puppet, and Docker setups for easy deployment; refer to the Sinopia readme at http://npm.im/sinopia for more details.

Finally, let's enter the directory of the hsl-to-hex module we've been building throughout this chapter, and publish it locally.

From the hsl-to-hex module folder, we run this:

npm publish 

We can see whether this worked by navigating to http://localhost:4873 in the browser:

Sinopia module viewer
Stop sinopia
We can stop Sinopia with killall sinopia, or taskkill /IM sinopia.cmd on Windows.
Revert to public registry
Set the npm registry back to default with
npm config delete registry.