In Search of Node Modules
3 min read
I know this seems funny, I am looking for my node modules. Are you looking for your node modules? Maybe not. For once, let us assume that you need to know where your node modules are. This article is about npm commands that help find where your node module is located and what node modules are installed. For this article, I will like to assume that you have Node.js and npm installed on your machine.
Finding locally installed node modules
To locate where the locally installed modules will be located or are placed. We use the command
npm root. If you are in a folder without any node modules installed and which has not being initialised using
npm init for a node package. The command returns the location where your node modules will exist. If you are in a folder with a node module installed or which has been initialised for a node package. The command returns the node modules location.
Here it returns the would-be location of the node_modules folder. if it existed.
Let us check for the installed modules in the node_modules folder returned in the image above using the
npm list command.
From the GIF above we can see that there are no node packages located in the
From the motion graphics below, we see that the
npm _commands folder is empty.
We install some packages into the folder using the
npm install <package name> command. Check for the
node_modules folder and the installed modules.
To check for the installed modules, we use the
npm list command used earlier.
Finding globally installed node modules
We know that locally installed node modules are located at the root of the package in the node_modules folder. So, where are our globally installed node modules?
To find the location we add the suffix
-g to the command we used earlier. So the command becomes
npm root -g.
The GIF above shows the location of where all globally installed modules are installed.
To list the modules installed globally, we add the suffix
-g to the command used earlier. The command becomes
npm list -g.
npm list or
npm list -g also returns the dependency in each installed module. To avoid displaying the dependency use suffix
This article has shown how to find the location of node modules installed locally and globally and how to list out each module. All from the comfort of your command line application.