Skip to content

Instantly share code, notes, and snippets.

@damonsk
Created September 4, 2013 20:12
Show Gist options
  • Save damonsk/6442247 to your computer and use it in GitHub Desktop.
Save damonsk/6442247 to your computer and use it in GitHub Desktop.
// bah.js
module.exports.bah = function(){
function ponies(){
return "hai";
}
};
// test.js
var bah = require("./bah");
console.log(bah.ponies());
@RyanGough
Copy link

you're assigning the proprety "bah" on the exports object to be a function. That function contains a definition of a function called "ponies" but its not assigned to a property of bah so you can't access it in this way.

if you just want to export the ponies function, easiest way is to just do

module.exports.ponies = function(){return "hai";}

then you can do

var bah = require("./bah"); // bah is assigned the "module.exports" object from bah.js file which has ponies property
console.log(bah.ponies());

@RyanGough
Copy link

a good way to sanity check this stuff is to fire up the node repl and do require("./bah.js") and it will show you what is being exported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment