Exporting a named module
// myfancyname.js
exports.myfancymethod = function () {
console.log('Hello, myfancyname!');
}
// app3.js
var myfancyname = require('./myfancyname.js');
myfancyname.myfancymethod();
- Create the two files above and then run
node app3.jsin the terminal. What do you see? - Update
myfancyname.jswith some of your own code insidemyfancymethod. - Add another
exports:myotherfancymethodwith some of your own code inside.