How to know if a module is installed in node

I know that I can install a module in node.js using npm install module-name. but try that multiiple times and it will install again. I am tired of forgetting that I have installed modules globally and I am installing them again. How do I know if a module installation already exists globally in node?

you have to try

npm ls

will give you the list of installed modules

to list global packages

npm ls -g

to list global packages with more detail

npm ls -gl

same way to list local packages with detail

npm ls -l

also you can type

npm help ls

for more details regarding this

If you want to know whether you have a specific module installed, you can run npm explore <module>. If you get an error, then you don't have that module and you should download it.

This is a bit of a hack, but it works.