Node modules folder in forked github repo?

About 9 months ago or so I successfully forked a node-red github repo and have been updating the .html and .js files ever since using vscode, regularly committing the changes to my forked repo. One thing I did notice is that in my forked repo a node_modules folder shows, which does not show in the original repo. I have not added any additonal node.js libraries. In fact, looking at the contents of that node_modules folder, I don't recognize any of the files.

The reason I ask is that the original maintainer has given me collaborator status and as such I now have push-access. However I do not want to push the node_modules folder in my forked repo to the original repo, which does not have that folder. Should I be worried about this at all? Is there anything I can try/test before actually pushing my fork to the original repo?

This is my first coding project using vscode and using github and it has been quite the learning experience. So I apologize in advance for my ignorance or if this question has been asked and answered before. Just point me in the right direction and I will take it from there.

Thanks,
Joe

You should have a .gitignore file and it should contain various things like node_modules and others.

Here is a reasonable example: https://github.com/microsoft/vscode-samples/blob/master/.gitignore

And here is a write-up: Gitignore Explained: What is Gitignore and How to Add it to Your Repo

As for why it exists: it contains necessary dependencies that are installed when npm install is executed. Typically, it contains all of the dependencies and developer dependencies mentioned in the adjacent package.json and many of them can/will be dependents of the dependencies.

In short, never commit node_modules

1 Like

Steve,

thanks, that helps. So just to be clear, should I just delete the node_modules folder in my forked repo?

Joe

OK got it. Added .gitignore file, committed to online repo and deleted node_modules folder from online repo.

Thanks again for helping out on this,
Joe

1 Like

So now that I am familiar with .gitignore and node_modules folder (thank you @Steve-Mcl) I have 2 follow-on questions:

  • Should I include package-lock.json in .gitignore? I'm guessing yes, but just thought I'd check.

  • If so, can I then safely remove package-lock.json from my github repo, like I did with the node_modules folder? Again, I'm guessing yes as from everything I have read on package-lock.json it gets created when doing an npm install.

Joe

There are 2 schools of thought with regards to the package lock.

Personally, I don't but I'm some cases it is beneficial e.g. for teams of developers to get the exact same dependency versions installed.

In the case of a simple node red node package that a lone developer works on, I'd say don't bother publishing the package lock (exclude it via git ignore)

1 Like

Understood and good point on the development team aspect.

Thanks again,
Joe

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.