My Situation
I’m developing a Node.js application as npm module.
In order to be able to run this app, I installed all the npm dependencies. So, my project contains some ./node_module/ folders containing external module dependency builds.
I maintain my project using git and I publish using a GitHub repository.
My Problem
I don’t want to publish all my local builds of the npm module dependencies on GitHub.
I only want to publish my own code. The users of my module should use npm install to get the current builds dependencies.
My Question
What’s the best way to keep the dependency builts away from my GitHub repository?
Thanks for your answer (or comment). – If anything’s unclear, please comment.
In the root directory of your project (the one above
node_modules) add the following line to the end of your .gitignore file (create it if needed):That will prevent the node_modules files from being added to the GitHub repository.
Then create or open the package.json file in that same directory, and add a
dependenciessection like so:Generally, you’ll want to use 0.0.x for the format of your versions. This ensures you get bug fixes but no breaking or major changes in your dependencies, so they will stay compatible with your module.
The package.json will tell npm to install anything listed in
dependencieswhenever your module gets installed. You can read more about package.json here.And here is a great little overview of the entire process.