user1394625 user1394625 - 1 year ago 116
Node.js Question

Node.js how to find local node_modules folder from a globally installed package

I'm writing my own CLI node module 'npak' that is installed globally.

I need to find the absolute path of the local 'node_modules' folder of a project where the (the global) cli command was executed.

say the project looks like this:

/folder-three/ npak find-modules
^-- this should return absolute path of node-modules folder

should return : /home/projects/test-project/node-modules even though npak is installed globally

How do I get at the absolute path of the local 'node-modules' folder regardless of what the cwd is from a globally installed package?

Answer Source

There are some useful modules, like find-node-modules, that can help you with such a task.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download