Developing and Testing NPM packages locally


In order to build a npm packages you might need to take several days or weeks to get your package “publish ready”.

During the course of development you will definately want to test locally quite often to ensure stability of your module.

This is a short guide on doing exactly that.

First, create your package if you haven’t done so already. It’s best practive to fill in the information in the package.json file that is greated after issuing npm init.

npm init

Code your module. This part is up to you.

Package your module.

npm pack

Once packaged, it’s possible to install your newly created package to test it. You don’t need to install it globally unless you really need to. You can simply run it in a /bin directory in your Node project root.

Leave the directory of where the module was packaged.

cd ..

Issue the following install command to make your package available system-wide.

npm install /directory/some-package-1.0.0.tgz
$ your-package

If you want to use your package globally you simply install with the -g parameter.

npm install /directory/some-package-1.0.0.tgz

At this point you can run your package from anywhere.

$ your-package

This short guide is designed to cover the basics. For additional information on creatin npm packages we suggest you visit npm’s Getting Started guide.

Leave a Reply