• Home
  • About
  • Contact
  • Speaking

Private npm registry with fallback to global registry

by Piotr Stapp — on nodejs devops 13 Jan 2016

The requirement

From time to time we need to use npm packages on following machines:

  • Continuous Integration build agent
  • with no access to internet (usually CI agent)
  • with slow internet proxy

Moreover as Windows developers we have Windows servers.

Prerequisites

There are few mostly obvious prerequisites. I will list them to make sure You won't forget about anything:

  • Windows server (or Linux one) - can be a simple virtual machine
  • Installed nodejs from https://nodejs.org/
  • Installed and configured CTLM (if your proxy need this)

Sinopia

Sinopia is a private/caching npm repository server. To install it just run:

npm install sinopia -g  

To "run" it just create a new directory, enter it and start sinopia

mkdir sinopia  
cd sinopia  
sinopia  

Two important things just happened:

  1. In your profile a config.yaml file was created (something like C:\Users\XXXXXX\AppData\Roaming\sinopia\config.yaml)
  2. The server started on default port (enter URL in browser to see it)

Config in global dir is cool but useless. So let's copy it to current dir and run sinopia with:

sinopia.cmd --config .\config.yaml  

Useful configuration

There are some points we should add or change in configuration:

  • Changing the port to "normal" one like 80 or 8080. In the end of config.yaml we need to add:
listen:  
 - 0.0.0.0:80              # listen on all addresses (INADDR_ANY)
  • Add proxy with
http_proxy: http://localhost:3128/  
https_proxy: http://localhost:3128/  
no_proxy: localhost,127.0.0.1  
  • Depends on your proxy change https://registry.npmjs.org/ to http://registry.npmjs.org/

To verify if everything above is working just run again:

sinopia.cmd --config .\config.yaml  

Create a Windows service

Because I mainly work on Windows environment I need to run above a Windows service.
I decided to use winser package.
The easiest usage is to create package.json and add commands in it.

Sum up

All above stuff and changes I put in simple github repo. If you find any error contact me and I will fix it. Just clone, fix port if you need and run npm install as windows administrator.


Follow @ptrstpp950

0%
Private npm registry with fallback to global registry
words - read.
Recent Posts:

Comments

comments powered by Disqus
Piotr Stapp Author

Piotr Stapp

Developer, engineer, craftsmen, speaker & biker. User of all useful technologies. Believe in people not papers. DevOps & automation adept. In love with web technologies. I speak here for myself only.

Previous post Clean code - regular expressions The most important thing I learn in 2015 is about clean code. It is everything. You can have a…
Next post ReAttach - how to easily (re)attach the debugger in Visual Studio In more complicated projects, simple F5 doesn't compile&debug. In cases where you're working with IIS (w3wp process)…
All content copyright Reset your code © 2016 • All rights reserved.
Proudly published with Ghost