DEV Community

Avinash Dalvi
Avinash Dalvi

Posted on

How to test NPM package locally

I started contributing to Angular and NPM packages. One of main issue i faced is how to debug this NPM package locally before committing.

I tried search around StackOverflow and Medium. Found NPM has one best think is npm link and npm unlink. Using this command you can create symbolic link to local package to global node_modules or inside Angular project node_modules

Here is documentation available for npm link and npm unlink https://docs.npmjs.com/cli/link

First tried running command npm link inside NPM package and npm link foldername this foldername is same NPM package folder name. But this didn't work.

Why ?

  • Because package name was using author name in package. It called as scope in node modules. In my case its something like this @username/foldername.

How do link this ?

  • Same as normal command only mention npm link @username/foldername and for Angular project npm link @username/foldername. This name generally from package.json

And what ?

Its works like rocket...πŸš€πŸš€πŸš€πŸš€

Top comments (1)

Collapse
 
ksadralodabai profile image
Keyvan Sadralodabai

This is great. Thank you.