I have a question. please forgive my lack of knowledge since I am a beginner
when we push our code Github or anywhere else for hosting, obviously we push everything without the node_modules folder.
Then how do all the third-party libraries work in the hosted website since the node_modules folder wasn’t added and all the libraries are dependent on the node_modules folder?
I have been wondering for a lot of time now.
2
Answers
When you create your production build, the needed node_modules are build into a single js file (depending on your configuration ofc), so once you’ve got the production build, that includes everything for the site to work.
You don’t push the node_module to GIT because it’s reproducible by running eg
npm install
after cloning the project, no need to save such data to GIT.Every
libraries
that needs to be installed is included in thepackage.json
file. Upon deploying your application, there will a build step in which the libraries will be installed by simply runningnpm start
which installs thelibraries
listed in thepackage.json
file.So no need to include such huge
node_modules
folder as it can be reproduced.