Download: WebM (10 MB) MP4 (22 MB)
Episode 3: Modules
Modules are the building blocks of Node.js applications. Find out how to use them and how to create your own.
Links
Module Demonstration
circle.js
var pi = 3.14;
exports.circumference = function(radius) {
return radius * radius * pi;
};
exports.area = function(radius) {
return 2 * radius * pi;
};
app.js
var circle = require('./circle');
var radius = 1;
console.log("Circ. with radius = 1:", circle.circumference(radius));
console.log("Area with radius = 1:", circle.area(radius));
Log in to add your comment!
thx
This definitely can be a huge impact on the budding Nodejs community. Keep up the great work!
also there is a question :
what kind of module definition is better ? define in variable and then export [maybe it make some hoisting problem] or define them directly in export content , or eaven define in module.export ! which one is the best pattern to development ?
thx