DEV Community

Hamza
Hamza

Posted on

why does NPM install extra modules?

I am new to web development, currently learning Node.js and Express is the first web framework i am diving into, since that's the stack the online course i am following work with (and i am quite happy with it).
While trying to to npm install Express to the directory i am working in, i have noticed that not only express module was install but also a bunch of other modules:

node_modules

So, my questions is: What's the need for all those extra modules? and are they necessary for express to function well?

and Thanks in advance

Top comments (8)

Collapse
 
connorphee profile image
Connor Phee

Hamza,

The reason for all of those extra modules is that Express depends on those. If you check out Express on NPM: npmjs.com/package/express

you can see the dependency list on the right side of the page matches those extra packages in your node_modules.

This is common for larger packages since it is much easier to find an existing package that solves a problem, rather than having to write it from scratch, similar to how you're using Express to simplify/abstract some things.

Also worth noting: Not only are the dependencies of Express installed, but also the dependencies of the dependencies, and that goes for every level until every needed package exists.

Hope this helps!

Collapse
 
salahhamza profile image
Hamza

I couldn't find a simpler answer, you really explained everything I wanted to know and some more.
Thank you so much Connor

Collapse
 
theodesp profile image
Theofanis Despoudis

There is a well known joke about node modules...

node_modules

Collapse
 
ardennl profile image
Arden de Raaij

Even though it's so true, I'm still happy with it. I remember Ruby Dependency hell and it wasn't pretty..

Collapse
 
hrmny profile image
Leah • Edited

I still think it could be better and people should think twice before including new dependencies

Especially when there's nested dependencies

Collapse
 
salahhamza profile image
Hamza

Haha, but i suppose it's better that way, I'll get to look up a the dependencies of the module I'm installing and so I'll know that module better than if it included every thing itself.

Collapse
 
joshualjohnson profile image
Joshua Johnson

Node installs all modules required by any modules you depend on. In the case of express. It has a number of modules that have to be pulled in to properly run.

Collapse
 
salahhamza profile image
Hamza

Yes, so it seems! Cause I was wondering what are all these modules, am I doing something wrong, turns out npm installed what it's supposed to.
And that's why I love programming I learn something new every time I ask a question.
Thank you Joshua