Last active
August 29, 2015 14:11
-
-
Save cjpartridgeb/2c23f8bb57518eed1a08 to your computer and use it in GitHub Desktop.
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
function randomPosts(count, callback) { | |
entry.count(function (err, count) { | |
if(err) return callback(err); | |
async.times(count, function(n, done) { | |
var r = Math.floor(Math.random() * count); | |
entry.find({}, null, {limit: 1, skip: r}, function(err, post) { | |
if(err) return done(err); | |
return done(null, post[0].content); | |
}); | |
}, callback); | |
}); | |
} | |
var express = require('express'); | |
var app = express(); | |
app.set('view engine', 'ejs'); | |
app.set('views', ''); | |
app.get('/', function (req, res) { | |
randomPosts(10, function(err, posts) { | |
res.render('list', { | |
p: posts | |
}); | |
}); | |
}); | |
app.listen(3000, function () { | |
console.log("ready") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment