.\" generated with Ronn/v0.4.1 .\" http://github.com/rtomayko/ronn/ . .TH "NPM\-JSON" "1" "May 2010" "" "" . .SH "NAME" \fBnpm\-json\fR \-\- Specifics of npm's package.json handling . .SH "DESCRIPTION" npm aims to implement the commonjs\fIPackages\fR spec. However, some adjustments have been made, which may eventually be unmade, but hopefully will be incorporated into the spec. . .SH "overlay" npm responds to the \fBnode\fR and \fBnpm\fR env\-specific package.json values, which you can hang on any of the following keys: \fB"overlay", "env", "context", "ctx", "vnd", "vendor"\fR. . .P For example: . .IP "" 4 . .nf { "name" : "foo" , "version" : 7 , "description" : "generic description" , "overlay" : { "node" : { "name" : "bar" , "description" : "description for node" } , "npm" : { "version" : "1.0.7" , "description" : "description for npm" } , "narwhal" : { "description" : "description for narwhal" } } } . .fi . .IP "" 0 . .P In this case, this is what npm will treat it as: . .IP "" 4 . .nf { "name" : "bar" , "version" : "1.0.7" , "description" : "description for npm" } . .fi . .IP "" 0 . .P This way, even if npm is not exactly the same as some other package management system, you can still use both, and it can be a happy planet. . .SH "version" Version must be \fIsemver\fR\-compliant. npm assumes that you've read the semver page, and that you comply with it. Versions packages with non\-semver versions will not be installed by npm. It's just too tricky if you have more than one way to do it, and semver works well. . .P (This is actually mentioned in the Packages/1.0 spec, but it's worth mentioning that npm enforces this requirement quite strictly, since it's pretty liberal about most other things.) . .SH "dependencies" The Packages/1.0 spec's method for specifying dependencies is Unclean in My Sight. So, npm is using a very simple semver\-based method. . .P Dependencies are specified with a simple hash of package name to version range. The version range is EITHER a string with has one or more space\-separated descriptors. . .P Version range descriptors may be any of the following styles, where "version" is a semver compatible version identifier. . .IP "\(bu" 4 \fBversion\fR Must match \fBversion\fR exactly . .IP "\(bu" 4 \fB=version\fR Same as just \fBversion\fR . .IP "\(bu" 4 \fB>version\fR Must be greater than \fBversion\fR . .IP "\(bu" 4 \fB>=version\fR etc . .IP "\(bu" 4 \fB=version1 <=version2\fR. . .IP "" 0 . .P For example, these are all valid: . .IP "" 4 . .nf { "dependencies" : { "foo" : "1.0.0 \- 2.9999.9999" , "bar" : ">=1.0.2 <2.1.2" , "baz" : ">1.0.2 <=2.3.4" , "boo" : "2.0.1" } } . .fi . .IP "" 0 . .SH "link" You may specify a \fBlink\fR member in your package.json to have npm link dependencies in to a particular location inside your package dir. For example: . .IP "" 4 . .nf { "dependencies" : { "boo" : "2.0.1" , "baz" : ">1.0.2 <=2.3.4" , "foo" : "1.0.0 \- 2.9999.9999" , "bar" : ">=1.0.2 <2.1.2" } , "link" : { "boo" : "./deps/boo" , "baz" : "./lib/baz" , "foo" : "./deps/foo" , "bar" : "./deps/bar" } } . .fi . .IP "" 0 . .P This would link the dependencies into the specified locations, so that the package code could do \fBrequire("./deps/foo")\fR to import whichever version of \fBfoo\fR was satisfying the requirement. . .P \fBWarning!\fR This is currently the \fIonly\fR way in which npm modifies the pristine nature of the package directory, and it may go away eventually. It's just that it satisfies a use case that is pretty tricky to do otherwise. . .SH "engines" Packages/1.0 says that you can have an "engines" field with an array of engine names. However, it has no provision for specifying which version of the engine your stuff runs on. . .P With npm, you can use either of the following styles to specify the version of node that your stuff works on: . .IP "" 4 . .nf { "engines" : [ "node >=0.1.27 <0.1.30" ] } . .fi . .IP "" 0 . .P or: . .IP "" 4 . .nf { "engines" : { "node" : ">=0.1.27 <0.1.30" } } . .fi . .IP "" 0 . .P And, like with dependencies, if you don't specify the version (or if you specify "*" as the version), then any version of node will do. . .P If you specify an "engines" field, then npm will require that "node" be somewhere on that list. If "engines" is omitted, then npm will just assume that it works on node. . .SH "bin" A lot of packages have one or more executable files that they'd like to install into the PATH. npm makes this pretty easy (in fact, it uses this feature to install the "npm" executable.) . .P To use this, supply a \fBbin\fR field in your package.json which is a map of command name to local file name. On install, npm will link that file into place right next to wherever node is installed. (Presumably, this is in your PATH, and defaults to \fB/usr/local/bin\fR.) On activation, the versioned file will get linked to the main filename (just like how the main.js stuff works, but with an executable in the PATH.) . .P For example, npm has this: . .IP "" 4 . .nf { "bin" : { "npm" : "./cli.js" } } . .fi . .IP "" 0 . .P So, when you install npm, it'll create a symlink from the \fBcli.js\fR script to \fB/usr/local/bin/npm\-version\fR. Then, when you activate that version, it'll create a symlink from \fB/usr/local/bin/npm\-version\fR to \fB/usr/local/bin/npm\fR. . .P (props to \fImikeal\fR for the idea)