Node.js modules pushed to GitHub

Viewed 10296

I am trying to push my project to GitHub and Heroku. Since I am using Node.js in my app, I have folder node_modules. Before I commit I have created a file called .gitignore to ignore the Node.js modules.

Inside the file I have added folder node_modules and tried to push to the GitHub repository from the comandline/Terminal. I was not expecting the Node.js modules to be pushed, but they appeared finally in the repository. Is there an ways I have to follow?

Here is how I resolve my issue

 - $ git rm -r --cached node_modules

Add folder node_modules/ to your .gitignore file:

 - $ git commit -m "remove the ignored directory node_modules"

And then

 - $ git push origin master

After that, if you refresh the GitHub page you will see the node_modules folder gone.

5 Answers

Create a .gitignore file in your directory and insert this:

.gitignore
node_modules

It worked for me perfectly. It is also an easier way to get rid of Node.js modules for newbie coders.

Related