Skip to content

Instantly share code, notes, and snippets.

@emanuelpessoaa
Last active April 15, 2016 23:33
Show Gist options
  • Save emanuelpessoaa/a5674e4fdb8432ed19b1898058817ead to your computer and use it in GitHub Desktop.
Save emanuelpessoaa/a5674e4fdb8432ed19b1898058817ead to your computer and use it in GitHub Desktop.
NodeJS Modularization with Callback
//module example.js
var exports = {};
exports.search = function(firstName, lastName, callback) {
this.thedude = {};
this.thedude.name = firstName + ' ' + lastName;
callback(this.thedude.name);
};
module.exports = exports;
//end of example.js
//module whatever.js
var module_example = require('./example.js');
module_example.search('Big', 'Lebowski', function(err, data){
console.log(err, data); // « 'Big Lebowski'
});
//end of whatever.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment