Skip to content

Instantly share code, notes, and snippets.

@jaxbot
jaxbot / callback-equivalent.js
Last active August 29, 2015 14:05
Node.js generators vs. callbacks
function home() {
db.query("SELECT * FROM `posts` ORDER BY `time` DESC LIMIT 10", function(err, rows){
render('home', { posts: rows[0] }, function(err, result){
response.end(result);
});
});
}
function post(id) {
db.query("SELECT * FROM `posts` WHERE `link` = " + db.escape(id)), function(err, rows){
@repeatingbeats
repeatingbeats / nodeunit_example.js
Created January 27, 2011 20:07
Example structure for nodeunit tests with nested groups and setUp/tearDown functions
/**
* Example structure for nodeunit tests with nested groups and setup/teardown
* functions. Run | nodeunit nodeunit_example.js | to see a printout of
* function names in the order that they are called. There aren't any actual
* tests here.
*/
process.env.NODE_ENV = 'test';
var testCase = require('nodeunit').testCase;