Last active
August 29, 2015 14:09
-
-
Save madhums/3cd999ada8ecacd04df3 to your computer and use it in GitHub Desktop.
structure for writing module/api in node
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
/** | |
* Module dependencies. | |
*/ | |
var http = require('http'); // native modules first | |
var mongoose = require('mongoose'); // npm modules second | |
var config = require('config'); // modules that are required via NODE_PATH third | |
var fmt = require('./format-date'); // local modules fourth | |
var oauth = require('../../oauth'); // relative modules last | |
/** | |
* Expose | |
*/ | |
module.exports = Main; | |
/** | |
* main | |
* | |
* @param {Object} options | |
*/ | |
function Main (options) { | |
// body... | |
} | |
/** | |
* fetch | |
* | |
* @param {Object} item | |
* @param {Function} cb | |
* @return {Main} | |
*/ | |
Main.prototype.fetch = function (item, cb) { | |
// body... | |
}; | |
// exports | |
/** | |
* perform | |
* | |
* @param {Request} req | |
* @param {Response} res | |
*/ | |
exports.fetch = function (req, res) { | |
// body | |
}; | |
// private functions | |
/** | |
* request | |
* | |
* @param {Object} options | |
* @param {Function} cb | |
*/ | |
function request (options, cb) { | |
// body... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment