Testing npm package locally
In this blog, we will look into how to test a npm
package. Check the below link on how to create one
To test your npm package locally before deploying it, we will use the npm link
command.
- Run the below command in your package directory (where the local version of the npm package is present)
npm link
- Run the below command in your app directory where you want to test your package
npm link package-name
This is an excellent option :) when it works.npm link
has been around all the way back to npm@1.0
, long before build steps were the norm and browser JS was a part of npm, and the adoption of these tools has introduced some problems.
There are few main problems I've run into.
- The package can be uninstalled using the same uninstall or rm command that can be used for removing installed packages.
The only thing to keep in mind is that the link needs to be uninstalled globally — the --global
the flag needs to be provided.
Uninstalling Package
In order to uninstall the globally linked package say foo
, the following command can be used (using sudo
if necessary, depending on your setup and permissions)
sudo npm rm --global foo
This will uninstall the package.
Happy coding 💻