Search code examples
javascriptnode.jsnode-modulesnode.js-stream

what is difference Between Package and Module in node.js


By using command npm install upper-case i can download upper-case package. However by using this command var upperCase = require('upper-case') i can use upper-case module.

So, what's the difference between module and package in this context. Are they same?


Solution

  • The way to call modules in Node js is that after executing the file with EX: node index.js, it will refer to the side folders and before us and look for the node_modules folder.

    when you using var upperCase = require('upper-case') Node js go to node_modules folder and open upper_case folder and open package.json and read this line "main": "upper-case.js". this line say to node, that you should for starting this module running upper_case.js and in this file there is another module that require it, similar upper_case.

    But you cannot use the modules in the packages of each module. They are dependencies of the same module and for your program you have to define dependencies and modules of your own and install them individually. This is the nature and essence of Node js and is designed to use modules like this.