Added Nginx, Node and Redis project
Signed-off-by: ajeetraina <ajeetraina@gmail.com>
This commit is contained in:
9
nginx-nodejs-redis/web/Dockerfile
Normal file
9
nginx-nodejs-redis/web/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM node:alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ./package.json ./
|
||||
RUN npm install
|
||||
COPY ./server.js ./
|
||||
|
||||
CMD ["npm","start"]
|
15
nginx-nodejs-redis/web/package.json
Normal file
15
nginx-nodejs-redis/web/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "web",
|
||||
"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"
|
||||
}
|
23
nginx-nodejs-redis/web/server.js
Normal file
23
nginx-nodejs-redis/web/server.js
Normal file
@@ -0,0 +1,23 @@
|
||||
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('Number of visits is: ' + numVisitsToDisplay);
|
||||
numVisits++;
|
||||
redisClient.set('numVisits', numVisits);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(5000, function() {
|
||||
console.log('Web application is listening on port 5000');
|
||||
});
|
Reference in New Issue
Block a user