Ad

NodeJS, NPM, And Package.json Dependencies

After reading npm-json (npm help json), I have construct the package.json file as follows: {"name": "app name", "version": "0.1"}. The directory has the following structure:

/
|-- main.js
|-- package.json

I am familiar with Node.js - do I need to reinstall all the modules on the production server when deploying the Node.js app, thus I have tried to install the dependencies by executing npm install moduleDep --save, but I am getting the following error:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', 'jquery', '--save' ]
2 info using [email protected]
3 info using [email protected]
4 verbose read json /home/roth/develop/build/package.json
5 error Error: invalid version: 1
5 error     at validVersion (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:582:40)
5 error     at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:342:23)
5 error     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:140:33
5 error     at cb (/usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:48:11)
5 error     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:48
5 error     at fs.js:117:20
5 error     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:53:5
5 error     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:62:5
5 error     at Object.oncomplete (fs.js:297:15)
6 error If you need help, you may report this log at:
6 error     <http://github.com/isaacs/npm/issues>
6 error or email it to:
6 error     <[email protected]>
7 error System Linux 3.1.10-1.16-desktop
8 error command "node" "/usr/local/bin/npm" "install" "jquery" "--save"
9 error cwd /home/roth/develop/build
10 error node -v v0.8.18
11 error npm -v 1.2.2
12 verbose exit [ 1, true ]

Before I can run the main module, I have to use NPM for installing the dependencies. Is there any command which I can execute that will install and then add the dependency to the package.json? A thorough explanation will be great.

Ad

Answer

Node.js uses a 3 part versioning system like '0.0.1' or '1.2.3' - your '0.1' won't work. This is called semantic versioning, and it's detailed here:

http://semver.org/

The basic idea is that you use three numbers that stand for major, minor, and patch (major.minor.patch).

You can read more here about npm's versioning:

http://blog.nodejitsu.com/package-dependencies-done-right

Ad
source: stackoverflow.com
Ad