Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.)

share|improve this question
1  
What do you mean "package.json has no parameters?" – Jesse Fulton Feb 8 '12 at 2:31
E.g.: To install mongodb with native c++ parser you need to do: npm install mongodb --mongodb:native. I have not figured out how to pass this native part to npm when using a package.json. – TheHippo Feb 8 '12 at 11:39
add comment (requires an account with 50 reputation)

3 Answers

up vote 5 down vote accepted

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.

References:

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

share|improve this answer
Thanks for the tip with parameters passed to npm in general! I will include the npm command in a bash script or a Makefile and we are good to go... – TheHippo Feb 20 '12 at 17:55
npmjs.org/doc/shrinkwrap.html could have helped.... – TheHippo Feb 27 '12 at 6:02
add comment (requires an account with 50 reputation)

Here's a good article that explains when you should and shouldn't check your node_modules into git. May answer your questions.

node_modules in git

share|improve this answer
1  
Prefer npmjs.org/doc/shrinkwrap.html – Ricardo Stuven Mar 14 '12 at 16:47
It's worth reading both the given article and the link about node-shrinkwrap – Hari Karam Singh Jan 24 at 17:18
add comment (requires an account with 50 reputation)

Afaik, the only ways to do package management are what you've described although I'm unsure as to what you're uninterested about wrt package.json.

If you want tight control over the versions of the modules your using you can explicitly specify the version number. You can also use the >=X.X.X approach as well to automatically grab the latest (above a threshold) which is sometimes fine for development purposes.

This allows your teammates to do:

npm install .

Which will install all the dependencies listed inside the package.json file. These will install to ./node_modules but you can .gitignore that as you noted.

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.