#3: Modules :: NodeCasts: Free Node.js Screencasts

Episode 3: Modules

Published Aug 13, 2026 · 7:25 runtime · 13 comments

Modules are the core building blocks of any Node.js application. In this episode you'll see how to work with existing modules and how to write your own from scratch.

Nodecasts logo
Nodecasts
Download WebM (10 MB) Download MP4 (22 MB)

Show Notes

This episode was recorded using Node.js v0.8.6.

Downloads · Documentation

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));

Comments

Eugen F avatar
Eugen F, 14 years ago
Brandon Tilley avatar
Brandon Tilley, 14 years ago
AdamBenAron avatar
AdamBenAron, 14 years ago
Alex Bezuska avatar
Alex Bezuska, 14 years ago
Prem Pillai avatar
Prem Pillai, 14 years ago
DeannRie avatar
DeannRie, 14 years ago
unknown avatar
unknown, 13 years ago
rmyock avatar
rmyock, 13 years ago
mohammad baniasad avatar
mohammad baniasad, 12 years ago

Eugen F, 14 years ago: Hey man, nice screencasts! When can we expect continued? :)

Brandon Tilley, 14 years ago: Thanks, Eugen! A definite schedule hasn't shaken out yet, but for now I'm aiming for a minimum of one per week.

AdamBenAron, 14 years ago: Hey, really great screencasts, I like them much better than others I've seen. thx

Alex Bezuska, 14 years ago: Another awesome episode, thanks again!

Prem Pillai, 14 years ago: Amazing quality! I learned all my Ruby (and Rails) from Railscasts. This definitely can be a huge impact on the budding Nodejs community. Keep up the great work!

DeannRie, 14 years ago: Thank you for interesting video.

unknown, 13 years ago: Fantastic! Looking forward to more of these.

rmyock, 13 years ago: MOAR!!!!

mohammad baniasad, 12 years ago: thanks thanks :)

Ali Pour Zahmatkesh, 11 years ago: That was great. good quality and easy to learn. 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

skybedy, 11 years ago: Perfect for me. Thank you very much.

Manish, 11 years ago: Awesome!!

Paul1987, 10 years ago: Exceptional video. Clear and informative!

Log in to add your comment!

Frequently Asked Questions

What are modules in Node.js?
As this episode explains, modules are the building blocks of Node.js applications. They allow you to break functionality into separate files that can be loaded and reused throughout your program.
How do I use a module in Node.js?
You bring a module in with require(). In the demo, app.js loads the local circle.js file via var circle = require('./circle'); and then invokes the exported functions.
How do I create my own module?
Make a file and attach the values or functions you want to share onto the exports object. The circle.js example in this episode exports circumference and area functions that other files can require.
What is the difference between exports and module.exports?
Both expose values from a module. This episode's example uses exports.circumference and exports.area to attach functions to the module's exports.
Where can I find the official module documentation?
The show notes link out to the Node.js module documentation, which explains the module system in depth.
Which Node.js version is used in this episode?
This episode was recorded with Node.js v0.8.6. The show notes include links to that version's downloads and documentation.

Copyright © 2012 Brandon Tilley

Node.js is an official trademark of Joyent. This site is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.

If you're new to Node.js, this episode is a good starting point: it shows how a single require() call can pull in a local file, and how the exports object turns that file into a reusable module. Try recreating the circle.js and app.js examples yourself, then experiment with adding your own functions to the exports object.