Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
structure for writing module/api in node
/**
* 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
You can’t perform that action at this time.