Created
September 4, 2013 20:12
-
-
Save damonsk/6442247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bah.js | |
module.exports.bah = function(){ | |
function ponies(){ | |
return "hai"; | |
} | |
}; | |
// test.js | |
var bah = require("./bah"); | |
console.log(bah.ponies()); |
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());
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
TypeError: Object # has no method 'ponies'
at Object. (C:\SourceCode\Bitbucket\test.js:3:
17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3