Skip to content

Instantly share code, notes, and snippets.

@bhurlow
Forked from jhs/example.js
Last active October 13, 2015 20:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhurlow/4248545 to your computer and use it in GitHub Desktop.
Save bhurlow/4248545 to your computer and use it in GitHub Desktop.
My Node.js modules these days
// assets
// first installed modules
var util = require('util')
var assert = require('assert')
var whatever = require('whatever')
// then local
var foo = require('./foo')
var bar = require('./bar')
// main export
module.exports = the_exported_function
module.exports.extra = extra
module.exports.other = other
var ENABLE_BUGS = false
, MODE = 'production'
function the_exported_function() {
}
function extra() {
}
function other() {
}
function main() {
}
// IF RUN DIRECTLY via node <filename>.js
if(require.main === module) {
// do stuff here
}
// otherwise its a module
else {
module.exports = the_exported_function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment