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.
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.
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.
Check node_modules into git for things you deploy, such as websites and apps. Do not check node_modules into git for libraries and modules intended to be reused. Use npm to manage dependencies in your dev environment, but not in your deployment scripts.
Never push node_modules. So now that you understand that your dependencies are system specific and might include native modules, you should never assume that your node_modules folder will work in production.
5, Any particular downside of committing node_modules? The downside is that you'll have a hard time scaling your app horizontally this way also it may happen that some dependencies change in the mean time. Well in my case it is less likely that I'll need to scale it horizontally in next 6–10 months.
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):
node_modules
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 dependencies
section like so:
{
"dependencies": {
"module": "0.0.x",
...
}
}
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 dependencies
whenever your module gets installed. You can read more about package.json here.
And here is a great little overview of the entire process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With