Should we ignore both node_modules and package.json files when pushing to a remote repo?

Hello guys, sorry to disturb you all... I have a quick question. I read that when creating a github repository and when pushing js files that uses external node libraries, we should ignore the node_modules since this will affect performance. Should I still upload the package.json file?
11 Replies
Jochem
Jochem3d ago
you should ignore anything that is generated, or downloaded by a tool that you can run an "install" of and is then used without modification package.json is the recipe list that lets npm install download your node_modules, so it should be in your repo as without it, there's no way to reproduce your application to a working state node_modules should never end up in a repo though
Faker
FakerOP3d ago
oh yeah I see
ἔρως
ἔρως3d ago
another good reason to do not shove node_modules in your repo is that it can get MASSIVE!!!
Faker
FakerOP3d ago
yep, this will decrease pull and push performance one question....it's been a long time I haven't touch those things but each time we want to use external libraries, we should set up an npm init? so that we keep track of what libraries we have used etc etc in the package.json? I think it's also necessary when we use nodemon?
Jochem
Jochem3d ago
each project where you intend to install packages with npm should start with npm init, yes
Faker
FakerOP3d ago
yep I see, if we don't do that and try to install package directly, like npm i <package_name>, we get an error?
Jochem
Jochem3d ago
yeah though if you use a framework, the init is often done as part of the installation of the framework itself so just follow the framework's instructions on how to start a new project
Faker
FakerOP3d ago
Yep I see, thanks ! Just tested it out, I tried to install express, like npm install express, we don't really get an error, it does install the library with package.json generated but our package.json doesn't contain much info about the project, just the dependencies
Jochem
Jochem3d ago
seems like it runs init for you now, instead of giving you an error also, how would it contain info about the project if you didn't give it any?
Faker
FakerOP3d ago
yep but it doesn't produce much details though yeah xd it just have the key "dependencies" nothing else, so I guess it's always good practice to npm init
Jochem
Jochem3d ago
if you're not using a framework, and intend to use npm, yeah

Did you find this page helpful?