-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.1 KB
/
index.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
var express = require("express");
var app = express();
var BodyParser = require("body-parser");
var Maths = require("./maths");
app.use(express.static(__dirname + '/public'));
app.get("/something", function(req, res){
res.send("hi from the something route");
})
app.get("/square/:num", function(req, res){
var num = req.params.num;
var squaredNumber = Maths.square(num);
var numberString = new String(squaredNumber);
res.send(numberString);
})
app.get("/sum/:num1/:num2", function(req, res){
var num1 = req.params.num1;
var num2 = req.params.num2;
var summedNumber = Maths.sum(num1, num2);
res.send("" + summedNumber);
})
app.get("/subtract/:num1/:num2", function(req, res){
var num1 = req.params.num1;
var num2 = req.params.num2;
var subtractedNumber = Maths.subtract(num1, num2);
res.send("" + subtractedNumber);
})
var port = process.env.NODE_ENV === "testing" ? 9001 : 9000;
var server = app.listen(port, function(){
var host = server.address().address;
var port = server.address().port;
console.log("running on", port, host)
});
module.exports = app;