I built a small Node.js app and I want to put it on GitHub but the problem is node_modules is so large. Is there is any way to build the app and make it small?
Asked
Active
Viewed 1,783 times
0
-
Typically you would *not* upload the content of `node_modules/` to version control, just the `package{,-lock}.json` files that allow you to install the correct dependencies in another environment. What you build would also not be included in version control, as that's generated not source code. – jonrsharpe Jun 07 '20 at 14:23
-
@jonrsharpe so how can I do it , is there any doc or video to follow ? – Jun 07 '20 at 14:38
-
Do what? If you mean remove node_modules, see e.g. https://stackoverflow.com/a/48301829/3001761. – jonrsharpe Jun 07 '20 at 14:40
1 Answers
1
To store you project on GitHub without node_modules you need to create a .gitignore
in the root of your porject (beside the package.json
file) and add node_modules entry to it.
The structure should look like this:
/project
...
package.json
.gitignore
package-lock.json // should NOT be added to the gitignore
And .gitignore
should look look like this
node_modules
After that you need to push this .gitignore
file to the remote repo (in your case to the GitHub).
By doing this you tell git to not track files which are inside the node_modules folder.
After pulling your project from remote (from GitHub) you will be able to get your modules back by using npm install
which will install your dependencies inside node_modules folder.

Roman Mahotskyi
- 4,576
- 5
- 35
- 68