awesome-compose/nginx-nodejs-redis/web/server.js
Ajeet Singh Raina, Docker Captain, ARM Innovator, RedisInc 04f8c9ca12
Nginx/Node/Redis and Flask/Redis Compose example (#222)
* Added Node, Nginx and Redis Project
* Added Flask/Redis
2022-03-17 17:33:36 +01:00

25 lines
687 B
JavaScript

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');
});