DEV Community

Cover image for Handling node_modules Being push to repository in Node powered projects.
ADEOYE ADEFEMI OPEOLUWA
ADEOYE ADEFEMI OPEOLUWA

Posted on

2 2

Handling node_modules Being push to repository in Node powered projects.

In my experience, working with mono-repo projects, I almost often end up adding node_modules to my remote repo 😩.

I finally found a way of working around it, hope to share. It's gonna be brief. But should you need to grab a cup of coffee, now is a good time to do that.

Let's Get Started

A typical mono-repo project I've worked with has a following folder structure similar to this
folder structure

With each folder having it own package.json file and node_modules folder
detailed structure of mono-repo

The pitfall

A common mistake is running

git add .
Enter fullscreen mode Exit fullscreen mode


` in any of the folder other than the root directory, this add all content of the folder (and node_modules too πŸ˜•) to the git history.

Way out

I found out adding .gitignore to each folder (api, client in this case) with the following content
`

./node_modules
Enter fullscreen mode Exit fullscreen mode



and

./api/node_modules
./client/node_modules
Enter fullscreen mode Exit fullscreen mode


in the root folder will make sure node_modules is not added to the remote repository even if you run

git add .
Enter fullscreen mode Exit fullscreen mode


`
in any of the folders having node_modules

fixing the error

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more