DEV Community

Frontend vintner
Frontend vintner

Posted on

Clarification on NPM

Hello, I just learned about npm and I'll like to get more clarification on usage of npm in web development(especially frontend development). From what I learned, npm installs packages to a local directory while cdn gives access to packages on a server. So this is where I get confused, if, for instance, I host my git repository on netlify, how would my site access the packages since I didn't upload npm modules?

Top comments (4)

Collapse
 
jwp profile image
John Peters • Edited

When web pages load their content is downloaded to make it work. There are two ways to get the content. CDN or via a NPM package.

The package.json file lists all npm installed packages. When compiled, that content exists in your distribution folder. At load time that content is used.

CDNs deliver the same content but all that content exists on their servers.

Collapse
 
lolyparty profile image
Frontend vintner

Thank you. I'm learning about bundling already.

Collapse
 
samjarman profile image
Sam Jarman πŸ‘¨πŸΌβ€πŸ’»

Hey! Good question. I see your confusion and it’s totally fine!

Npm modules do install stuff locally but often the install instructions each module should clear this up.

Generally speaking, when you build your website/web app for hosting on a website, the building tool (webpack, gulp, etc) will do all that work of getting the modules (or the subset youre using) into the package you upload (sometimes called compiling or bundling)

Do keep reading about this though - there are quite a few concepts here that you’ll definitely need to get your head around to continue down this path - and well worth learning :)

Collapse
 
lolyparty profile image
Frontend vintner

Thank you. I've started learning about bundling using webpack.