npm-prefix
Show npm installation prefix
TLDR
Print the local prefix
Print the global prefix
SYNOPSIS
npm prefix [-g|--global]
npm prefix [path]
PARAMETERS
-g, --global
Operates in global mode. When specified, npm prefix will output the global installation prefix instead of the local project prefix.
path
An optional argument specifying a directory. If provided, npm prefix will output the prefix for that specific path. If omitted, it defaults to the current working directory.
DESCRIPTION
The npm prefix command is used to output the local or global installation prefix for npm packages. The prefix is the directory where npm installs dependencies. When run without any arguments, it prints the root directory of the current project, which is where local node_modules are installed. If the -g or --global flag is provided, it prints the global installation prefix, which is the directory where globally installed packages and their executables reside. Understanding the prefix is crucial for debugging installation issues, managing paths for executables, and knowing where npm expects to find or place packages. It essentially tells you the base directory for npm operations, either project-specific or system-wide.
CAVEATS
The local prefix is typically the root of your project directory (where your package.json file resides). The global prefix can vary significantly depending on how Node.js and npm were installed (e.g., via nvm, Homebrew, or a direct installer). Modifying the prefix directly via npm config set prefix <path> can change npm's behavior for package resolution and installation, so exercise caution. Ensure your PATH environment variable is correctly configured to include the global bin directory (often $PREFIX/bin) to access globally installed executables.
CONFIGURATION
The prefix can be configured via npm config set prefix <path>. This sets a persistent default prefix for subsequent npm operations. You can check the current configuration with npm config get prefix.
USE CASES
Useful for scripting to determine installation locations, verifying expected directory structures, or troubleshooting issues where packages aren't found in the expected place. For example, to find where a global executable might be installed, you'd combine npm prefix -g with npm bin -g.


