Installing and Testing Verdaccio | Task

Ole Ersoy
Feb - 24  -  3 min

Scenario

We want to use Verdaccio for our local NPM Packages.

Approach

npm install -g verdaccio

Execute the CLI command:

verdaccio warn --- config file  - /home/.config/verdaccio/config.yaml warn --- http address - http://localhost:4873/ - verdaccio/3.0.0

Set Verdaccio as the local registry:

npm set registry http://localhost:4873/

Or use the http option when installing:

npm install --registry http://localhost:4873

Start Verdaccio by running:

verdaccio

You should see the following printed on the console:

 warn --- config file  - /home/ole/.config/verdaccio/config.yaml
 warn --- Verdaccio started
 warn --- Plugin successfully loaded: verdaccio-htpasswd
 warn --- Plugin successfully loaded: verdaccio-audit
 warn --- http address - http://localhost:4873/ - verdaccio/4.4.0

Add yourself as a user:

npm adduser --registry http://localhost:4873

Testing

npm publish

Visit http://localhost:4873

You should see your package published.

Now install the package in a local project:

mkdir testinstall
cd testinstall
npm init -y
npm install -S untyped-npm-module

You should see untyped-npm-module installed and the install should be logged on the Verdaccio console:

http <-- 200, user: ole(127.0.0.1), req: 'GET /untyped-npm-module/-/untyped-npm-module-1.1.1.tgz', bytes: 0/338
 http <-- 200, user: ole(127.0.0.1), req: 'GET /untyped-npm-module/-/untyped-npm-module-1.1.1.tgz', bytes: 0/338

Bonus

If you want to make sure that you only publish your package to Verdaccio include the following in the package.json file:

"publishConfig":{
    "access": "restricted",
    "registry":"http://localhost:4873"
}

Note that in order for this to work the package has to be scoped . For example Firefly Semantics packages are scoped with @fireflysemantics/.

So for example Slice is has the name:

@fireflysemantics/slice

Switching Back to NPM

If you need to publish a package to NPM you must set the registry to NPM again. Run:

npm config set registry https://registry.npmjs.org/

Resetting the Database

Stop verdaccio with ctrl+c.

Go to your settings. In my case they are located in:

~/.config/verdaccio/config.yaml

Look for the storage location. My configuration looks like this:

# path to a directory with all packages
storage: /home/ole/.local/share/verdaccio/storage

Remove all the packages in the storage directory:

rm -fr ~/.local/share/verdaccio/storage/

Start verdaccio:

verdaccio

Visit:

http://localhost:4873/

It should tell you that no packages are installed. Login again in order to be able to publish to verdaccio:

npm adduser --registry http://localhost:4873