Skip to content

Instantly share code, notes, and snippets.

@infynyxx
Created July 3, 2010 04:45
Show Gist options
  • Save infynyxx/462316 to your computer and use it in GitHub Desktop.
Save infynyxx/462316 to your computer and use it in GitHub Desktop.
Node.js Module Loading Incompatibility
/*This will work when loaded as module*/
exports.area = function(radius) {
return PI * radius * radius;
};
exports.circumference = function(radius) {
return PI * 2 * radius;
}
/*This will not work when loaded as module*/
var exports = {};
var PI = 3.14;
exports.area = function(radius) {
return PI * radius * radius;
};
exports.circumference = function(radius) {
return PI * 2 * radius;
}
var circle = require('./module_load_correct'), //module_load_incorrect
sys = require('sys');
sys.puts('The area of circle with radius 4 is ' + circle.area(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment