You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
687 B
JavaScript
25 lines
687 B
JavaScript
3 years ago
|
const os = require('os');
|
||
|
const express = require('express');
|
||
|
const app = express();
|
||
|
const redis = require('redis');
|
||
|
const redisClient = redis.createClient({
|
||
|
host: 'redis',
|
||
|
port: 6379
|
||
|
});
|
||
|
|
||
|
app.get('/', function(req, res) {
|
||
|
redisClient.get('numVisits', function(err, numVisits) {
|
||
|
numVisitsToDisplay = parseInt(numVisits) + 1;
|
||
|
if (isNaN(numVisitsToDisplay)) {
|
||
|
numVisitsToDisplay = 1;
|
||
|
}
|
||
|
res.send(os.hostname() +': Number of visits is: ' + numVisitsToDisplay);
|
||
|
numVisits++;
|
||
|
redisClient.set('numVisits', numVisits);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
app.listen(5000, function() {
|
||
|
console.log('Web application is listening on port 5000');
|
||
|
});
|