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
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 thoughoh yeah I see
another good reason to do not shove
node_modules
in your repo is that it can get MASSIVE!!!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?each project where you intend to install packages with npm should start with npm init, yes
yep I see, if we don't do that and try to install package directly, like npm i <package_name>, we get an error?
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
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 dependenciesseems 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?
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
if you're not using a framework, and intend to use npm, yeah