awesome-compose/nginx-nodejs-redis/web2/server.js
ajeetraina 657dc7c97f Added Nginx, Node and Redis project
Signed-off-by: ajeetraina <ajeetraina@gmail.com>
2022-03-13 17:02:24 +05:30

25 lines
650 B
JavaScript

const express = require('express');
const redis = require('redis');
const app = express();
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('web2: Total number of visits is: ' + numVisitsToDisplay);
numVisits++;
redisClient.set('numVisits', numVisits);
});
});
app.listen(5000, function() {
console.log('Web app is listening on port 5000');
});