Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Best workflow using node.js npm and git

Best workflow using node.js npm and git


I am about to do a large project with node.js and currently try sort a few things out.

In earlier node projects I had an extra folder for all node modules I used. This folder was ignored by git and I managed version and updates via git submodules, which was not easy (no dependencies, updating to new version was not always fun.)

What I am looking for is:

npm install packagename
npm dump_modules_into_file

So everyone else who is involved in this project could do:

npm install_or_update_modules_from_file

I don not want to have node_modules tracked by my git repository. Basically I want something similar to how symonfy2 handles it bundles.

P.S.: I know about npm submodule packagename, but this command is not very helpful because it does not install dependencies and it does not update the modules.

P.S.2: I ready about the package.json, but this also has some flaws. (No parameters and you have to update module versions by hand.)

Problem courtesy of: TheHippo


package.json will accomplish what you're looking for. In your comment about passing the --mongodb:native flag, that flag is an argument to the npm command and does work when using a package.json in your own project. The mongodb package has an "install script" which looks for that flag in the node processing environment. If that flag is present, then it spawns another process for the build. So, if you have mongodb as a dependency in your package.json

    "name": "MyProject"
  , "description": "Test"
  , "version": "0.0.1"
  , "dependencies": {
        "mongodb": "*"

Running npm install --mongodb:native will work.

With regards to "updating it by hand" - it's really only the first time that it might take a while, and I'm sure you could write a script to generate it if there are a lot of dependencies. However, it sounds like you have a fairly large team, and if that is the case, then automating the updates to package.json will turn really ugly (think new developers, experimental features, etc.) Having accountability for broken builds in this part of the development cycle isn't necessarily a bad idea.


  • (see "scripts" section)

EDIT: and as Nick mentioned, adding the 'node_modules' directory to .gitignore will prevent any of those files from being checked into your repo

Solution courtesy of: Jesse Fulton


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Best workflow using node.js npm and git


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription