Is It Common to Have Multiple node_modules Folders in One Project?

0
6
Asked By TechExplorer92 On

I'm currently building an application and started by running `npm init -y` in the root directory, which created a package.json and a node_modules folder there. Later on, I ran the same command again to set up a specific package.json for the backend, intending to install Prisma locally. This resulted in another node_modules folder being created. I'm wondering if it's normal to have more than one node_modules in a project, especially considering the space it takes up. Am I doing something wrong? Can someone clarify this for me?

3 Answers

Answered By NodeWizard On

Ideally, you shouldn't mix multiple repositories in the same root folder like that—it can complicate things. Having separate node_modules for different package.json files is generally acceptable, but be cautious.

Answered By CodeMaster88 On

Yes, it's pretty common based on how you've structured your project. If you're using workspaces, there'll be a node_modules in the root and potentially one for each sub-package too. Just make sure you're clean about dependency management so things don’t get confusing!

PrismaPro22 -

Thanks for the insight! I was worried about having redundant folders.

Answered By DevGuru17 On

It's totally fine to have multiple node_modules folders as long as they are in separate project directories. For example, if you have a structure like this:

root/
|- node_modules
|- package.json
|- project_a/
|- node_modules
|- package.json

That keeps everything organized. If your setup is more nested, like having 'backend' within the root, that's still acceptable. However, if you don’t really need that structure, you might consider restructuring your projects a bit.

WebDevNinja -

Got it! My setup looks like this after running npm init -y:

root/
|- node_modules
|- package.json
|- backend/
|- node_modules
|- package.json

So this structure should be fine?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.