-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 1.2 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
const express = require("express");
const bodyParser = require('body-parser');
const app = express(); //we call the entire package express and save it inside of another constant called “app”
app.use(bodyParser.urlencoded({extended: false }));
//this backend code lives inside of some server.
app.get("/", function(req, res)
{
// console.log(req);
res.sendFile(__dirname + "/index.html");
//console.log(__dirname); //getting the exact location of the directory where this backend code is located(in which port, which server, etc).
});
app.post("/", function(req, res)
{
// res.send("The back-end has received the POST Request.");
var num1 = Number(req.body.n1); //from the body of the request that has been created by the urlencoded method of body-parser, we need to get the access to the n1 data.
var num2 = Number(req.body.n2);
var result = num1 + num2;
res.send("Addition of the two numbers : " + result);
})
app.get("/about", function(req, res)
{
// console.log(req);
res.send("About kanu seth : hehehehe");
});
//creating a web server - 3000.
app.listen(3000, function()
{
console.log("Server has started on port 3000.");
});
//your backend code needs to continuously run.