Difference between a node module and a package in Node.js?
Node package
A node package is a file or directory and it is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry.
Example
Shapes <- Package name - Circle.js <- - Rectangle.js <- Modules that belong to the Shapes package - Square.js <- - package.json <- Must have this to be a package
Node module
A node module is any file or directory in the node_modules directory. A module is loaded by the Node.js require() function.
Example
- API.js <- Modules - package.json <- Optional to have
Note: Since modules are not required to have a package.json file, not all modules are packages. Only modules that have a package.json file are also packages.
Node package | Node module |
---|---|
A package must contain a package.json file | Modules are not required to have a package.json file |