Where are you — node modules?

Michie Riffic
MichieRiffic
Published in
2 min readAug 20, 2016

Installing npm modules globally (-g) in your terminal using

USER$ npm install moduleName -g

is easy breezy. People instruct you to do this and that. But have you ever wondered where they’re really stored?

To find the list of your node-modules that was installed globally, all you have do to is change directory to the following path:

USER$ cd /usr/local/lib/node_modules

NOTE: cd in terminal means change directory

So it is actually stored in the

/USR > LOCAL > LIB > NODE_MODULE directory (or folder)

Now if you just installed them within the app the you are working on:

:directoryLocation USER$ npm install moduleName

It will be saved on the node_modules folder in that current working directory.

So why save a node module in a certain project and why save it globally?

This depends on your preference. When you save it globally, it means that you are giving it the power to be used in whatever directory you are in or whatever project you are doing. Saving it on a specific project, limits the use of that module to a certain app or project that you are working on.

To decide whether what’s right for your node module, ask the following questions:

Will you be using this node module all the time on your different projects?

An example is Nodemon. Nodemon is a utility that will monitor for any changes in your source and restart your server automatically.
This will make your life more productive because you don’t have to restart your server over and over again. In this scenario, save this node module globally.

Will this node module be use one time or seldom in your projects?

An example is aws-sdk. AWS SDK for JavaScript will help you connect your project to the AWS platform. You probably would use this only on some your projects. In such case, saving it specifically to that project would be better.

Again, saving it on a specific project or globally still depends on your preference. This is just a suggestion.

For people who are unfamiliar with npm, npm is a node package manager.

Node package managers package reusable code that can easily be installed, shared and distribute to others.

So why not give npm a try and start finding node modules (reusable code) to play around with. Start assembling them and include them in your awesome projects.

NOTE: When you install node, npm is already installed with it.

To find modules that you like at https://www.npmjs.com.

If you enjoy this lesson, you can give it a ❤ or share it out. Thanks! :)

--

--