Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update obsolete code of index.js of example "online" #6153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions examples/online/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
// https://redis.io/

// then:
// $ npm install redis online
// $ npm install redis online-new
// $ redis-server

/**
* Module dependencies.
*/

var express = require('../..');
var online = require('online');
var redis = require('redis');
var db = redis.createClient();
const express = require('../..');
let online = require('online-new');
const redis = require('redis');

// online
const db = redis.createClient();
db.on('connect', () => {
console.log('Connected to Redis');
});
db.on('error', (err) => {
console.error('Redis Client Error', err);
});
db.connect();

online = online(db);

// app

var app = express();
const app = express();

// activity tracking, in this case using
// the UA string, you would use req.user.id etc

app.use(function(req, res, next){
app.use(async function(req, res, next){
// fire-and-forget
online.add(req.headers['user-agent']);
await online.add(req.headers['user-agent']);
next();
});

Expand All @@ -47,15 +47,12 @@ function list(ids) {
* GET users online.
*/

app.get('/', function(req, res, next){
online.last(5, function(err, ids){
if (err) return next(err);
res.send('<p>Users online: ' + ids.length + '</p>' + list(ids));
});
app.get('/', async function(req, res, next){
const ids = await online.last(5);
res.send('<p>Users online: ' + ids.length + '</p>' + list(ids));
});

/* istanbul ignore next */
if (!module.parent) {
if (require.main === module) {
app.listen(3000);
console.log('Express started on port 3000');
}