You are not logged in.

#1 2025-02-25 08:08:05

duyinthee
Member
Registered: 2015-06-14
Posts: 242
Website

npm install package only into ~/node_modules

As far as I understand by reading wiki and man page, npm install package in current directory.
That means, as I understand, if I cd into a directory at ~/dirA and I do npm install http-server will create ~/dirA/node_modules and the package will reside in it.
But it is not like that. Only ~/node_modules will be created and the package will reside in it.
That behaviour is being something wrong?

Offline

#2 2025-03-02 12:36:09

ms
Member
From: Bandung, Indonesia
Registered: 2010-07-28
Posts: 86
Website

Re: npm install package only into ~/node_modules

Based on the npm documentation [1]

> 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.)

So, in your case, the dirA does not have a package.json file but your $HOME does.

[1]: https://docs.npmjs.com/cli/v9/configuri … nformation

Last edited by ms (2025-03-02 12:37:07)

Offline

Board footer

Powered by FluxBB