Skip to content

Commit a675f6b

Browse files
author
dockeruser
committed
initial commit
0 parents  commit a675f6b

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:alpine
2+
3+
WORKDIR '/app'
4+
5+
COPY package.json .
6+
RUN npm install
7+
COPY . .
8+
9+
CMD ["npm", "start"]

docker-compose.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
3+
services:
4+
redis-server:
5+
image: 'redis'
6+
node-app:
7+
restart: on-failure
8+
build: .
9+
ports:
10+
- "4001:8081"
11+

index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const express = require('express');
2+
const redis = require('redis');
3+
4+
const app = express();
5+
const client = redis.createClient({
6+
host: 'redis-server',
7+
port: 6379
8+
});
9+
client.set('visits', 0);
10+
11+
app.get('/', (req, res) => {
12+
client.get('visits', (err, visits) => {
13+
res.send('Number of visits is: ' + visits);
14+
client.set('visits', parseInt(visits) + 1);
15+
});
16+
});
17+
18+
app.listen(8081, () => {
19+
console.log('Listening on port 8081');
20+
});

package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"dependencies": {
3+
"express": "*",
4+
"redis": "2.8.0"
5+
},
6+
"scripts": {
7+
"start": "node index.js"
8+
}
9+
}

0 commit comments

Comments
 (0)