Build NPM private bank (super simple)



The reason for my private library is very simple. I’m currently developing a component library for internal use. I don’t want to register NPM or wait for npm’s audit. I just want to have a repository to quickly test and publish my own NPM package.

How to build

At present, the most convenient solution is verdaccio, which is very convenient to build. It is usually completed in a few minutes. The tools needed are:

  • Installing nodejs and NPM
  • Global installation of verdaccio
  • Shh and PM2 (not required, if you want to deploy to a remote server)

Next, the steps of building are described in detail.

Global installation of verdaccio

Before installing verdaccio, I defaulted that everyone had already installed nodejs and NPM environments, which I won’t dwell on any more. If it’s built locally, just do the following. If it is built on a remote server, connect to the remote server via ssh.

# Global Installation
npm install verdaccio - g

Modify verdaccio configuration

The purpose of the configuration modification is to make our private library accessible through public network ip. First, we look at the location of the NPM global installation package.

npm root -g

among/usr/local/Cellar/node/8.4.0/lib/node_modulesThat’s the address where our NPM package is installed globally. Find the location of the configuration file by naming it as follows


vim default.yaml

The configuration is as follows

# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
# Look here for more config file examples:

# path to a directory with all packages
storage: ./storage
# path to a directory with plugins to include
plugins: ./plugins

  # WebUI is enabled as default, if you want disable it, just uncomment this line
  #enable: false
  title: Verdaccio

    file: ./htpasswd
    # Maximum amount of users allowed to register, defaults to "+inf".
    # You can set this to -1 to disable registration.
    #max_users: 1000

# a list of other known repositories we can talk to

    # scoped packages
    access: $all
    publish: $authenticated
    proxy: npmjs

    # allow all users (including non-authenticated users) to read and
    # publish all packages
    # you can specify usernames/groupnames (depending on your auth plugin)
    # and three keywords: "$all", "$anonymous", "$authenticated"
    access: $all

    # allow all known users to publish packages
    # (anyone can register by default, remember?)
    publish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

# You can specify HTTP/1.1 server keep alive timeout in seconds for incomming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue Set to 0 in case 60 is not enought.
  keepAliveTimeout: 60

# To use `npm audit` uncomment the following section
    enabled: true

# log settings
  - {type: stdout, format: pretty, level: http}
  #- {type: file, path: verdaccio.log, level: info}

# listen

The last additional configuration to support IP access to the extranet


Then enter:wqSave and exit the VIM mode and start the verdaccio service. I usually start through pm2, the reason is very simple, after closing the doc window, the service will not stop, and can manage the service we started well.

Using PM2

Common commands

  • Installation: NPM install pm2-g
  • Start: PM2 start verdaccio
  • Stop: PM2 stop verdaccio
  • Restart: PM2 restart verdaccio
  • Delete application: PM2 delete verdaccio
  • View logs: PM2 logs verdaccio

Let’s start the service and see the effect:

pm2 start verdaccio

So far, NPM’s private library has been set up. In the figure is a newly released component library based on Vue. Later, I will introduce the compilation and release of the component library. Interested friends will pay attention to the following.