Node.js has a simple module loading system that reduces complexity of applications and promotes code reusability.
Node.js has a simple module loading system that reduces complexity of applications and promotes code reusability. In Node.js, files and modules are in one-to-one correspondence.
For example, foo.js
loads the module circle.js
in the same directory:
The contents of foo.js:
var circle = require('./circle.js');
console.log( 'The area of a circle of radius 4 is ' + circle.area(4));
The contents of circle.js:
var PI = Math.PI;
exports.area = function (r) {
return PI * r * r;
};
exports.circumference = function (r) {
return 2 * PI * r;
};
Node.js also has an incredible community of open source developers who publish packages using npm: