Best way to test global npm modules

Lets say I develop a global npm module called mytool that registers a env variable through "bin" in package.json with the name mytool.

So after I install it globally by typing

npm install mytool -g

then I can type mytool --someOption in terminal and handle the CLI input in javascript. Now lets assume that mytool works a lot with the current working directory of the CLI, so to just

node index.js --someOption

is a bad idea.

However to test for bugs I don't want to push a new version of "mytool" to npm and then install it globally from npm. Rather I want to be able to test this all locally.

Question: What is the best way to do test global npm modules without publishing to npm?

Answers:

Answer

npm link

Contrary to what it seems, npm link can also be used in your case, too.

Just run it on the root folder of your project. No additional arguments are necessary.

Using it in you package folder will create a symlink in the global folder {prefix}/lib/node_modules/<package> that links to the package where the npm link command was executed.

It will also link any bins in the package to {prefix}/bin/{name}.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.