What is a dependency in a .json package - nodejs

In my projcet node, I create independent modules in a folder with main.js as an entry point and place the helpers for this module in the same folder as different files.

Ex: Aggregator: |___package.json |___main.js |___node_modules |_____helper1.js |_____helper2.js 

Therefore, node will resolve all the dependencies of my helper modules [Ex: Aggregator] from the local node_modules folder. The reason for the structure above, I do not need to care about the path to require

I use package.json to indicate that the entry point is main.js incase require for Aggregator

 Ex: //Sample.js require('Aggregator'); // Resolves to Aggregator/main.js 

Example: package.json aggregator module

  { "name": "Aggregator" , "description": "Returns Aggregates" , "keywords": ["aggregate"] , "author": "Tamil" , "contributors": [] , "dependencies": { "redis": "0.6.7" } , "lib" : "." , "main" : "./main.js" , "version" : "1.0" } 

Here's what the dependency column is for? I referred to this link. My code works even if I specify the redis version as 10000 without warning. I tried to remove the redis module from the project to check if it picks up the node and resolves the dependency, but that is not the case. When to use this dependency attribute in package.json? Is this just a note for future reference?

npm version 1.1.0-beta-4; node version v0.6.6

+4
source share
1 answer

The dependencies value is used to indicate any other modules that are required for this module to work (represented by package.json ). When you run npm install from the root folder of this module, it will install all the modules listed in this dependencies hash.

If you did not get any errors with redis: 10000 listed there, I assume that you never ran npm install , and therefore it did not even try to install redis. In turn, if your code works fine without executing npm install , most likely your code does not even need to be reused, and this element should be removed from the dependencies hash.

Although not every entry in package.json necessary for understanding everyday development, dependencies definitely important to know. I would recommend reading the dependency section on the npm website .

+6
source

Source: https://habr.com/ru/post/1412796/


All Articles