-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (36 loc) · 973 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
38
39
40
41
var express = require("express");
var app = express();
app.get("/", function(req, res) {
res.send("Hi there, welcome to my assignment!!");
});
app.get("/speak/:animal", function(req, res) {
var animal = req.params.animal;
var noise;
switch(animal) {
case "dog":
noise = "woof";
break;
case "cow":
noise = "moo";
break;
case "pig":
noise = "oink";
break;
default:
break;
}
res.send("The " + animal + " says " + noise);
});
app.get("/repeat/:string/:count", function(req, res) {
var string = req.params.string;
var count = parseInt(req.params.count, 10);
var response = "";
for (var i = 0; i < count; i++) {
response += string + " ";
}
res.send(response);
})
app.get("*", function(req, res) {
res.send("What are you doing with your life?");
});
app.listen(process.env.PORT, process.env.IP);