Setup local Verdaccio server to release NPM packages

Verdaccio is a fully featured NPM registry that you can run locally on your machine. It’s a great tool for testing your release process, running end-to-end tests, and simulating real-world scenarios like deploying packages, installing them, and verifying functionality as an end user would.

Nx includes a generator that simplifies setting up Verdaccio. To configure it, run:

npx nx g @nx/js:setup-verdaccio

This command installs the necessary NPM packages and creates a project.json file with a local-registry target. To start the local registry, open a new terminal window and run:

npx nx local-registry

This will:

  • Launch the Verdaccio registry.
  • Configure NPM to point to the local Verdaccio server at http://localhost:4873.

Note: A project.json file provides an advanced way to define scripts, offering more flexibility than a traditional package.json for managing complex targets.

Share with a coworker

Transcript

[00:00] Now there is a cool project that is called Verdasho and that allows you to run such a local npm registry on your machine and point your npm publishing URL location to that local machine such that then your package end up there instead of ending up on the public NPM. Now, to help you set this up, such as you don't have to run this on your own, NX comes actually with a generator to set this up for you in your workspace. And so since we already have the NXJS plugin installed, So if you go into the package.json at the root here we have this nxjs plugin or npm package which provides the versioning logic for java packages and this package specifically has also a generator and It's called setup-verdasha. And I'm going to run this now and you can see it creates here a verdasha config.yml file. It updates my package.json probably to install some packages like verdasha itself.

[00:58] And then it sets up here such a project.json which is actually nothing else if you haven't seen it yet, than the NX version of a package.json script. So rather than having a package.json script defined here, you can define a more, if you want, evolved version that defines your local registry target. So meaning you can run this with NX, you can run npx nx local registry, and we will do that in a second. And then you have some more options that are being provided to this setup. And so here you can see it runs the port, the actual config that has been created here at the local workspace.

[01:30] So you have now the .verdash and config.yml file which allows you to configure Verdash how long the cache is being set up etc. Like a bunch of different options and it also defines where the packages are being stored which is here in temp folder directly in our repo here under local registry and storage. So as mentioned, this is nothing else than a target that we can actually run. So if I now run an X local registry and I hit enter, you can see now it runs the Verdashu script and it sets up the register point to this new Verdashu server. And so if I go to this URL now I have a local instance of Verdasha running.

[02:05] Now we don't have any packages yet so let's have a look. So I keep this running I open up another terminal on the side and since we released the last version at 1.1.0 and we create a bunch of different commits in the meantime, we can actually go and release a new version. And so let's just run nx-release. And we don't need dry run right now, let's just go through. It creates our changelog and now it asks us whether we want to publish these versions.

[02:31] And so now we can say true. And so here you can now see it runs NX Redis publish. You can see it creates here the different tarballs, it zips up our packages and publishes them to our local version here with the tag latest. And if I move over here to Verdasho, I hit refresh. I now can see all of these different packages have been released with the recording version.

[02:51] If I go in here, I can see some details like the actual readme rendering, the dependencies that they potentially have, like in this case 2.0 and a bunch of different options.