Dmitri
Dmitri

Reputation: 36300

is package.json file used by node?

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?

Upvotes: 6

Views: 830

Answers (2)

AymenLoukil
AymenLoukil

Reputation: 46

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/

Upvotes: 1

vkurchatkin
vkurchatkin

Reputation: 13570

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.

Upvotes: 6

Related Questions