npm-root
Show npm package installation root directory
TLDR
Display path to the local node_modules directory
Display path to the global node_modules directory
SYNOPSIS
npm-root [-g | --global]
PARAMETERS
-g, --global
Specifies that the global `node_modules` directory should be returned. If not specified, the command attempts to locate the `node_modules` directory for the current project.
DESCRIPTION
The `npm-root` command, available after installing the `npm-root` package globally (e.g., `npm install -g npm-root`), helps determine the location of the global `node_modules` directory or the root of a specific npm package install. This is useful for scripting, debugging, or simply understanding where npm installs packages. It simplifies locating dependencies which can be challenging when using both local and global package installations.
The command provides different modes of operation which allow targeting local or global installations. By default, if ran inside an npm project directory `npm-root` will return local install directory. It is a small but convenient utility for developers who frequently need to work with the file system locations of npm packages.
CAVEATS
This command relies on npm's configuration and directory structure. If npm's configuration is corrupted or unconventional, the command might produce unexpected results. The package must be installed globally to be used.
USAGE EXAMPLES
Find the local `node_modules` directory (when inside an npm project):
`npm-root`
Find the global `node_modules` directory:
`npm-root -g`
OR
`npm-root --global`
ALTERNATIVES
Alternatively, the global node_modules path can be found by combining `npm config get prefix` and joining `/lib/node_modules`. This approach requires multiple commands.
HISTORY
The `npm-root` command is provided by the `npm-root` npm package. It was created to address the common need for developers to easily find the npm package installation directory, avoiding manual searching or assumptions about directory locations. It has gained popularity as a utility tool for developers who need this information in their daily workflow.
SEE ALSO
npm(1), npm-install(1), find(1)