Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

61 lines (50 sloc) 1.748 kb
express = require "express"
redis = require "redis"
idgen = require "idgen"
Engine = require("../src").Engine
redisClient = redis.createClient()
engine = new Engine
redis: redisClient
namespace: idgen()
app = express()
app.engine "jade", require("jade").__express
app.set "views", __dirname + "/views"
app.set "view engine", "jade"
app.use express.logger("tiny")
app.use express.bodyParser()
app.use app.router
# redis keys we are going to use
usersKey = "#{engine.namespace}:twitter:users"
followingKey = (username) -> "#{engine.namespace}:#{username}:following"
app.get "/", (req, res) ->
res.redirect "/user/" + idgen()
app.get "/user/:username", (req, res) ->
username = req.params.username
redisClient.sadd usersKey, username # lets keep track of how many users there are
redisClient.smembers usersKey, (err, users) ->
redisClient.smembers followingKey(username), (err, following) ->
engine.inbox username, 0, 25, (err, inbox) ->
engine.sent username, 0, 25, (err, sent) ->
res.render "twitter",
inbox: inbox
sent: sent
users: users
following: following
username: username "/tweet", (req, res) ->
username = req.body.username
activity = # approximation of protocol
published: new Date()
actor: username
verb: "tweet"
content: req.body.tweet.substring 0, 140 username, activity, (err) ->
res.redirect "back" "/follow", (req, res) ->
from = req.body.from
to =
redisClient.sadd followingKey(from), to # track following
engine.follow from, to, (err) ->
res.redirect "back"
app.listen 3000, ->
console.log "Starting twitter example"
Jump to Line
Something went wrong with that request. Please try again.