-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (31 loc) · 1010 Bytes
/
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
40
41
42
43
const express = require('express');
const app = express();
const PORT = process.env.PORT | 5000;
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html')
// res.send('welcome in my Area Calculator')
});
app.get('/circle', (req, res) => {
res.sendFile(__dirname + "/circle.html")
});
app.get('/triangle', (req, res) => {
res.sendFile(__dirname + '/triangle.html')
});
// post methods =-============
app.post('/triangle', (req, res) => {
const base = req.body.base;
const height = req.body.height;
const area = 0.5 * base * height;
res.send(`<h2> Area of Triangle is : ${area} </h2> `);
});
app.post('/circle', (req, res) => {
const radius = req.body.radius;
const area = Math.PI * radius * radius;
res.send(`<h2> Area of Circle is : ${area} </h2>`)
})
app.listen(PORT, () => {
console.log(`server is runnig at http://localhost:${PORT}`)
})