forked from kumarnishant/getting-started-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
42 lines (36 loc) · 1.23 KB
/
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
38
39
40
41
42
var express = require('express');
var app = express();
var cities = {cities:["Amsterdam","Berlin","New York","San Francisco","Tokyo", "Delhi"]}
app.get('/', function(req, res){
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify(cities));
res.end();
});
app.get("/error", (req, res) => {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end();
})
app.get("/timeout-test", (req, res) => {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.write('Hello\n');
setTimeout(function() {
res.end(' World\n');
}, 5000);
})
app.get("/redirect", (req, res) => {
res.redirect(302, '/health');
})
app.get('/health', (req, res) => res.send({"status": "OK", "time": new Date()}))
var port = process.env.PORT || 8080;
app.listen(port);
setInterval(function(str1, str2) {
console.log(str1 + " " + str2 + " "+makeid(10)+" args 2 "+process.argv);
}, 800, "Hello.", "How are you?");
function makeid(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
module.exports = app;