1
0
Fork 0
mirror of https://github.com/docker/awesome-compose.git synced 2025-04-25 18:28:07 +02:00

Added Nginx, Node and Redis project

This commit is contained in:
ajeetraina 2022-03-05 12:23:50 +05:30
parent 6531426a96
commit 22c1733e20
12 changed files with 183 additions and 0 deletions

View file

@ -0,0 +1,9 @@
FROM node:alpine
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm install
COPY ./server.js ./
CMD ["npm","start"]

View file

@ -0,0 +1,15 @@
{
"name": "web1",
"version": "1.0.0",
"description": "Running Node.js and Express.js on Docker",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.2",
"redis": "3.1.2"
},
"author": "",
"license": "MIT"
}

View file

@ -0,0 +1,24 @@
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('web1: Total number of visits is: ' + numVisitsToDisplay);
numVisits++;
redisClient.set('numVisits', numVisits);
});
});
app.listen(5000, function() {
console.log('Web app is listening on port 5000');
});