Skip to content
Myr

index.js

This file

Path

examples/online/index.js

56 lines · 965 bytes · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 6bc7574 point at it.

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 1–56why, one step back
1// first:
2// $ npm install redis online3// $ redis-server45/**6 * Module dependencies.7 */89var express = require('../..');10var online = require('online');11var redis = require('redis');12var db = redis.createClient();1314// online1516online = online(db);1718// app1920var app = express();2122// activity tracking, in this case using23// the UA string, you would use req.user.id etc2425app.use(function(req, res, next){26 // fire-and-forget27 online.add(req.headers['user-agent']);28 next();29});3031/**32 * List helper.33 */3435function list(ids) {36 return '<ul>' + ids.map(function(id){37 return '<li>' + id + '</li>';38 }).join('') + '</ul>';39}4041/**42 * GET users online.43 */4445app.get('/', function(req, res, next){46 online.last(5, function(err, ids){47 if (err) return next(err);48 res.send('<p>Users online: ' + ids.length + '</p>' + list(ids));49 });50});5152/* istanbul ignore next */53if (!module.parent) {54 app.listen(3000);55 console.log('Express started on port 3000');56}