-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.js
More file actions
42 lines (26 loc) · 796 Bytes
/
calculator.js
File metadata and controls
42 lines (26 loc) · 796 Bytes
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
const express = require("express");
const parser = require("body-parser");
const app = express();
const port =3000;
app.use(parser.urlencoded({extended: true}));
app.get('/', (req, resp) => {
resp.sendFile(__dirname+"/index.html");
});
app.post('/', (req, resp) => {
var num1 = Number(req.body.num1);
var num2 = Number(req.body.num2);
var result = num1 + num2;
resp.send("The result is "+ result);
});
app.get('/bmicalculator', (req, resp) => {
resp.sendFile(__dirname+"/bmiCalculator.html");
});
app.post('/bmicalculator', (req, resp) => {
var w = Number(req.body.num1);
var h = Number(req.body.num2);
var result = w /(h * h);
resp.send("The BMI is "+ result);
});
app.listen(3000, () => {
console.log('Listening on port ' + port);
});