6

Is package.json file used by node when the application starts or is it used only by the npm for installing dependencies?

What I really need to know is this: when I start the app using

node myapp

Is the package.json file read or ignored?

Dmitri
  • 34,780
  • 9
  • 39
  • 55
  • link your code. do you read from it? – agconti Jan 17 '14 at 16:23
  • In my code I don't read my own package.json. Ok, the underlying question is: if I have dependency in package.json like "mongodb": "~1.4.0", but I actually have only mongodb 1.3.3 installed in node_modules, will my app still start since node does not really read package.json? – Dmitri Jan 17 '14 at 16:46

2 Answers2

6

package.json is actually used by node itself. Here is the code: https://github.com/joyent/node/blob/master/lib/module.js#L101 Basically, when you require a directory, it checks if the directory has package.json and if does uses file from it's main property.

otherwise package.json is used only in npm, but nothings stops you from reading it in your code.

vkurchatkin
  • 13,364
  • 2
  • 47
  • 55
1

Of course it reads package.json ! You can define your application starting point (file) that will be called when you type node "appName".

To define that and other parameters (dependencies..etc) type : npm init and follow the console wizard.

You can check this guide : http://package.json.nodejitsu.com/