NPM installing package with multiple folders for package - node.js

I recently started a new node project and ran npm install *name* --save for both express and nodemon and noticed that 20-30 folders appear in my node_modules folder related to the two packages instead of just express and nodemon. This has never happened when I have run this command with previous projects. Is there any reason why this is happening now?
I expected my node_modules folder to only have "express" and "nodemon"
npm version: 3.3.6
node version: 5.0.0

Stumbled upon your post with a Google Search and thought I'd link the answer :
Your dependencies will now be installed maximally flat. Insofar as is
possible, all of your dependencies, and their dependencies, and THEIR
dependencies will be installed in your project's node_modules folder
with no nesting. You'll only see modules nested underneath one another
when two (or more) modules have conflicting dependencies.
See npm#3's release notes.

Related

NPM install bunch of packages not from package.json file

Using Visual Studio code as IDE but lately when I run the command - npm install from the app folder of the solution it installs around 374 items under "node_modules" instead of just installing the packages from the package.json file.
Can someone please provide some pointers for this behavior?
My versions:
node -v
v6.9.1
npm -v
3.10.8
Go to your node_modules folder and find one of the folders matching the libraries from your package.json file. Inside you will find another package.json which describes this library. It is most likely it will also have at least a couple of entries in dependencies section.
When you run npm install npm builds so-called 'dependency tree'. It starts with your top-level package.json and checks what dependencies needs to be installed, then (using its registry) it checks what are the dependencies of these dependencies and then their dependencies and so on...
It is prudent (but often neglected) to check what are the dependencies of the libraries you decide to use. Some of them might have licenses incompatible with yours. Some of them might need a ton of code to perform a simple thing. Many will use deprecated versions, which will spam your npm install log with warnings and might actually cause some conflicts with your other dependencies.

npm install generate more folders than needed

I've been using ember for a while and when I wanted to install the node dependencies of a project, I just needed to use npm install to create the folder node_modules with all the dependencies (as it's described in http://ember-cli.com/user-guide/).
Since I was using an old version of node I unisntalled node and npm and installed nvm with the versions node v5.0.0 and npm v3.3.6but now, when I try to use npm install to install the dependencies of a project as I used to do before, instead of the dependencies of the package.json file, I get many, many more from things I'm not sure where they come (I think they are dependencies that npm handles by itself in a globally way but now it's adding them to my project locally, but I'm not sure).
Why am I getting all those unknown (for me) dependencies?
Notice that, when I run ember new it generates the correct dependencies in node_modules but if I delete this folder and run npm install happens the same.
That's one of the changes introduced by npm v3.0:
Your dependencies will now be installed flat - by default. If
possible, all of your dependencies, and their dependencies, and their
dependencies will be installed in your project's node_modules folder
without nesting. Nesting will only occur when two or more modules have
conflicting dependencies.
Read more at http://www.felixrieseberg.com/npm-v3-is-out-and-its-a-really-big-deal-for-windows/

Local NPM modules not installing correctly

Local NPM modules are no longer installing correctly for me in my projects node_modules dir. This has just started happening.
I set up a test dir with a package.json:
{
"name": "test",
"version": "0.0.0"
}
Then ran this command:
npm install grunt --save-dev
This is what I get in my node_modules dir:
Opening the grunt dir you can see there’s no node_modules:
Some of the NPM modules that appear in the root are what appears to be NPM modules belonging to the grunt NPM module, and some I have no idea where they are coming from? E.g. abbrev, esprima, graceful-fs, etc.
I used to get this:
project
│
└───node_modules
| │
| └───grunt
|
└───package.json
I’ve tried completely removing Node.js and NPM from my machine (Mac OS X 10.10.5) following these instructions. Then reinstalling it outside of Homebrew (where it was previously installed) which didn’t change anything. Then completely removing Node.js and NPM again and reinstalling it with Homebrew but this time I applied this. Again this didn’t fix anything.
Not sure what’s going on?
This is expected behavior. When you install grunt, npm recursively installs all its dependencies. These may be put to grunt/node_modules or may be put on the same level as grunt (directly in the top level node_modules). Both these options will work, which is because of how node works: if grunt requires some package (for example, colors) and node does not find it in grunt's node_modules directory, node tries to find the package in the parent's dir, then in grandparents dir and so on.
Out of these two options, older npm versions prefer the first option, newer versions prefer second option (i.e. more flat dependency tree), which is exactly your case.
In your case, packages such as 'async' or 'colors' are grunt dependencies (check out its package.json), 'abbrev' is not direct dependency of grunt, but probably it is dependency of some other dependency.
More reading:
https://docs.npmjs.com/cli/dedupe
https://github.com/alexanderGugel/ied
https://docs.npmjs.com/cli/shrinkwrap

Why is npm install downloading other useless plugins into my node_modules folder? [duplicate]

I just run a simple npm install morgan in a folder and for some reason it adds all the sub dependencies to the parent folder. See image attached
Yes, this is a new feature in npm 3.x, you can read about it here:
https://github.com/npm/npm/releases/tag/v3.0.0
Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.
Basically, it now handles dependencies with as little nesting as possible.
Npm has changed the way they organize dependencies. So instead of 2 separate modules requiring the same dependency and installing them in their own node_modules folder. The dependency is only installed once at the same folder level the node module is installed at.

Where does meteor install npm packages referenced in packages.json?

After meteor installs npm packages:
npm: updating npm dependencies -- winston...
Npm.require results in module not found error, by inspecting the code and debugging via node-inspector, I discovered that putting a standard node_modules folder (installed via npm install) in .meteor folder in the root of my meteor app folder gets it to find it.
However when deploying to meteor.com or using any automated build-pack (like Heroku's) this might not be possible, I would rather have a scenario where I can link the automatically downloaded modules to the paths Npm.require looks in.
Any idea where it downloads the packages?
Thanks
For meteorite packages this would be:
/path/to/your/project/packages/package_name/.npm/package/node_modules/
For core meteor packages I guess this is
~/.meteor/packages/package_name/hash/npm/node_modules/

Resources