Created
July 1, 2021 11:26
-
-
Save rajivnarayana/05b00f3dd836aa4da20b8ca6240a09ae to your computer and use it in GitHub Desktop.
Revisions
-
rajivnarayana created this gist
Jul 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ const express = require("express"); const bodyParser = require('body-parser'); const app = express(); // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: false })) app.get("/", (req, res) => { res.status(200).send(`<h2>Guessing game</h2> Click here to get <a href="/addition">started</a> `) }) app.get("/addition", (req, res) => { res.status(200).send(`<form method="POST" action="/result"> <div> <label for="number1">Enter number 1</label> <input type="text" name="number1" /> </div> <div> <label for="number2">Enter number 2</label> <input type="text" name="number2" /> </div> <div> <input type="submit" value="Add" /> </div> </form>`) }) app.post("/result", (req, res) => { const value = +(req.body.number1) + (+(req.body.number2)); res.status(200).send(`The result is ${value}. Click here to add some <a href="/addition">more</a>`) }) app.listen(4000, () => { console.log(`Server started on port 4000`); })