Node modules path linux

Where does npm install packages?

Just so every one knows, installing without -g option will install a module to you working directory e.g. if you make a directory say ~/Desktop/tmp then cd ~/Desktop/tmp then do npm install appium then do ls you will see node_modules package-lock.json because you have installed a node module appium to your working directory . super confusing because -g should essentially be the default but is not.

When using nvm to manage multiple versions of node, it’s under $HOME/.nvm/versions/node/v15.9.0/lib where the directory will change depending on what version of node you are using. See github.com/nvm-sh/nvm/blob/master/README.md for more info on nvm. I found this directory with npm list -g | head -1 as stated in the selected answer.

23 Answers 23

Global libraries

You can run npm list -g to see which global libraries are installed and where they’re located. Use npm list -g | head -1 for truncated output showing just the path. If you want to display only main packages not its sub-packages which installs along with it — you can use — npm list —depth=0 which will show all packages and for getting only globally installed packages, just add -g i.e. npm list -g —depth=0 .

On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.

Windows XP — %USERPROFILE%\AppData\npm\node_modules
Windows 7, 8 and 10 — %USERPROFILE%\AppData\Roaming\npm\node_modules

Non-global libraries

Non-global libraries are installed the node_modules sub folder in the folder you are currently in.

You can run npm list to see the installed non-global libraries for your current location.

When installing use -g option to install globally

npm install -g pm2 — pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules (Use npm root -g to check where.)

npm install pm2 — pm2 will be installed locally. It will then typically be found in the local directory in /node_modules

Источник

Where does npm install packages? Find the install path

The npm packages installed locally will always be installed on the node_modules/ folder right in your current working directory.

For example, when you’re on a directory called project/ from the terminal, then it will be inside the project/node_modules folder.

The npm install command will find the node_modules/ folder on the current directory. It will create one when it doesn’t exist.

Globally installed npm packages location

Globally installed npm packages usually follow the installation path of your npm module.

The easiest way to know where the global modules are installed is to run the npm list -g command.

The command shows the path to your global node_modules/ folder:

  On macOS computers, npm will be installed under /usr/local/bin/npm soft link path.

The actual path to the npm package is under /usr/local/lib/node_modules . Any globally installed packages will end up in that path as well.

On Linux computers, you’ll find the global install location on /usr/local/lib/node_modules as well.

On Windows computers, global npm packages should be installed under the roaming/ folder.

The example path is as follows:

Like in Unix-based systems, you can use the npm list -g command to find your global node_modules/ folder location:

Now you’ve learned how to find where npm packages are installed globally.

Global install using NVM

If you’re using NVM on your computer, then the packages you installed globally will be placed under the active Node version you’re using.

You can find the global node_modules/ folder location using the npm list -g command.

For example, suppose you’ve installed NVM on Windows under D:\ drive as shown below:

When you’re using Node v16.13.0 as the active version, then a global install will put the package under the v16.13.0/node_modules folder.

The same goes when you’re using Unix-based systems like Linux and macOS.

The installation directory of nvm may change to your Users/ folder as shown below:

The global packages will be installed under the active Node version lib/node_modules folder.

The absolute path looks as follows:

The $HOME variable points to your user directory in the system. You can also use the where nvm command to find your NVM installation location.

Now you’ve learned where npm installs packages on your computer. Always remember that you can find the global installation path using the npm list -g command. 👍

Learn JavaScript for Beginners 🔥

Get the JS Basics Handbook, understand how JavaScript works and be a confident software developer.

A practical and fun way to learn JavaScript and build an application using Node.js.

About

Hello! This website is dedicated to help you learn tech and data science skills with its step-by-step, beginner-friendly tutorials.
Learn statistics, JavaScript and other programming languages using clear examples written for people.

Type the keyword below and hit enter

Tags

Click to see all tutorials tagged with:

Источник

folders

npm puts various things on your computer. That’s its job.

This document will tell you what it puts where.

  • Local install (default): puts stuff in ./node_modules of the current package root.
  • Global install (with -g ): puts stuff in /usr/local or wherever node is installed.
  • Install it locally if you’re going to require() it.
  • Install it globally if you’re going to run it on the command line.
  • If you need both, then install it in both places, or use npm link .

The prefix config defaults to the location where node is installed. On most systems, this is /usr/local . On Windows, it’s %AppData%\npm . On Unix systems, it’s one level up, since node is typically installed at /bin/node rather than /node.exe .

When the global flag is set, npm installs things into this prefix. When it is not set, it uses the root of the current package, or the current working directory if not in a package already.

Packages are dropped into the node_modules folder under the prefix . When installing locally, this means that you can require(«packagename») to load its main module, or require(«packagename/lib/path/to/sub/module») to load other modules.

Global installs on Unix systems go to /lib/node_modules . Global installs on Windows go to /node_modules (that is, no lib folder.)

Scoped packages are installed the same way, except they are grouped together in a sub-folder of the relevant node_modules folder with the name of that scope prefix by the @ symbol, e.g. npm install @myorg/package would place the package in /node_modules/@myorg/package . See scope for more details.

If you wish to require() a package, then install it locally.

When in global mode, executables are linked into /bin on Unix, or directly into on Windows. Ensure that path is in your terminal’s PATH environment to run them.

When in local mode, executables are linked into ./node_modules/.bin so that they can be made available to scripts run through npm. (For example, so that a test runner will be in the path when you run npm test .)

When in global mode, man pages are linked into /share/man .

When in local mode, man pages are not installed.

Man pages are not installed on Windows systems.

See npm cache . Cache files are stored in ~/.npm on Posix, or %AppData%/npm-cache on Windows.

This is controlled by the cache configuration param.

Temporary files are stored by default in the folder specified by the tmp config, which defaults to the TMPDIR, TMP, or TEMP environment variables, or /tmp on Unix and c:\windows\temp on Windows.

Temp files are given a unique folder under this root for each run of the program, and are deleted upon successful exit.

When installing locally, npm first tries to find an appropriate prefix folder. This is so that npm install foo@1.2.3 will install to the sensible root of your package, even if you happen to have cd ed into some other folder.

Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective «current directory» for the purpose of running npm commands. (This behavior is inspired by and similar to git’s .git-folder seeking logic when running git commands in a working dir.)

If no package root is found, then the current folder is used.

When you run npm install foo@1.2.3 , then the package is loaded into the cache, and then unpacked into ./node_modules/foo . Then, any of foo’s dependencies are similarly unpacked into ./node_modules/foo/node_modules/. .

Any bin files are symlinked to ./node_modules/.bin/ , so that they may be found by npm scripts when necessary.

If the global configuration is set to true, then npm will install packages «globally».

For global installation, packages are installed roughly the same way, but using the folders described above.

Cycles, Conflicts, and Folder Parsimony

Cycles are handled using the property of node’s module system that it walks up the directories looking for node_modules folders. So, at every stage, if a package is already installed in an ancestor node_modules folder, then it is not installed at the current location.

Consider the case above, where foo -> bar -> baz . Imagine if, in addition to that, baz depended on bar, so you’d have: foo -> bar -> baz -> bar -> baz . . However, since the folder structure is: foo/node_modules/bar/node_modules/baz , there’s no need to put another copy of bar into . /baz/node_modules , since when it calls require(«bar»), it will get the copy that is installed in foo/node_modules/bar .

This shortcut is only used if the exact same version would be installed in multiple nested node_modules folders. It is still possible to have a/node_modules/b/node_modules/a if the two «a» packages are different versions. However, without repeating the exact same package multiple times, an infinite regress will always be prevented.

Another optimization can be made by installing dependencies at the highest level possible, below the localized «target» folder.

Consider this dependency graph:

foo
+-- blerg@1.2.5
+-- bar@1.2.3
| +-- blerg@1.x (latest=1.3.7)
| +-- baz@2.x
| | `-- quux@3.x
| | `-- bar@1.2.3 (cycle)
| `-- asdf@*
`-- baz@1.2.3
`-- quux@3.x
`-- bar

In this case, we might expect a folder structure like this:

foo
+-- node_modules
+-- blerg (1.2.5) ---[A]
+-- bar (1.2.3) ---[B]
| `-- node_modules
| +-- baz (2.0.2) ---[C]
| | `-- node_modules
| | `-- quux (3.2.0)
| `-- asdf (2.3.4)
`-- baz (1.2.3) ---[D]
`-- node_modules
`-- quux (3.2.0) ---[E]

Since foo depends directly on bar@1.2.3 and baz@1.2.3 , those are installed in foo’s node_modules folder.

Even though the latest copy of blerg is 1.3.7, foo has a specific dependency on version 1.2.5. So, that gets installed at [A] . Since the parent installation of blerg satisfies bar’s dependency on blerg@1.x , it does not install another copy under [B] .

Bar [B] also has dependencies on baz and asdf, so those are installed in bar’s node_modules folder. Because it depends on baz@2.x , it cannot re-use the baz@1.2.3 installed in the parent node_modules folder [D] , and must install its own copy [C] .

Underneath bar, the baz -> quux -> bar dependency creates a cycle. However, because bar is already in quux’s ancestry [B] , it does not unpack another copy of bar into that folder.

Underneath foo -> baz [D] , quux’s [E] folder tree is empty, because its dependency on bar is satisfied by the parent folder copy installed at [B] .

For a graphical breakdown of what is installed where, use npm ls .

Upon publishing, npm will look in the node_modules folder. If any of the items there are not in the bundleDependencies array, then they will not be included in the package tarball.

This allows a package maintainer to install all of their dependencies (and dev dependencies) locally, but only re-publish those items that cannot be found elsewhere. See package.json for more information.

Источник

Читайте также:  Astra linux драйвера видеокарты amd
Оцените статью
Adblock
detector