Last active
December 30, 2015 21:50
-
-
Save branneman/7890425 to your computer and use it in GitHub Desktop.
Example code style I use of a Node.js module. Uses @felixge's Node Style Guide and some more conventions on naming and formatting.
This file contains hidden or 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
// | |
// Articles controller | |
// Optional module description line. | |
// | |
'use strict'; | |
var fs = require('fs'); | |
var path = require('path'); | |
var Articles = require('./models/articles'); | |
var Comments = require('./models/comments'); | |
// Expose module | |
module.exports.index = indexAction; | |
module.exports.archive = archiveAction; | |
// Renders the latest articles | |
function indexAction(req, res) { | |
_render(res, 'index', Articles.getLatest()); | |
} | |
// Renders the archive, articles older than a year | |
function archiveAction(req, res) { | |
_render(res, 'archive', Articles.getArchive()); | |
} | |
// Render view | |
function _render(res, file, articles) { | |
res.render('articles/' + file + '.html', { | |
articles: articles | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment