-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (29 loc) · 774 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const Redis = require('ioredis');
const redisPort = 8369;
const checkRedisStatus = async (port) => {
const redis = new Redis({
port: port,
lazyConnect: true, // Avoids immediate connection
});
try {
await redis.connect();
console.log('Redis is running');
} catch (error) {
console.error('Redis is not running');
throw error;
} finally {
redis.disconnect();
}
};
checkRedisStatus(redisPort);
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});