Quick Tip — executable node modules
First of all, let's understand what does npm install -g does.
If you put a global identifier then npm install -g it is essentially installing all your packages to /usr/local/lib/node_modules
Additionally, if you have provided an executable in your package.json
example — “bin”: { “create-react-app”: “./index.js” }
then it will add create-react-app symlink to your index.js file in your system’s global executable bin folder.
/usr/local/bin/create-react-app symlink to /usr/local/lib/node_modules/create-react-app/index.js
Notice that an executable file need to specify the environment in the first line
#!/usr/bin/env node
All globally installed node modules can be “require”(available) in your node application.
Read here for more details on node path resolution. https://nodejs.org/api/modules.html#loading_from_node_modules_Folders
Let's say you installed the package locally instead of globally npm install {packagename} then you can still run it by directly executing the js in node.
$ node node_modules/lerna/bin/lerna.js
Or a better way — http://www.2ality.com/2016/01/locally-installed-npm-executables.html
If you like this tip, please click the 👏 button and share to help others find it!