Making Server with node and Express

Installation

$ npm install
$ npm install express

Express Code

const express = require(‘express’);const bodyParser = require(‘body-parser’);const cors = require(‘cors’);const app = express();let users = [];app.use(cors());app.use(bodyParser.urlencoded({extended:true}));app.use(bodyParser.json());app.post('/user',(req,res) =>{const user =req.body;console.log(user);users.push(user);res.send('user is added to the database');});app.listen(3001,()=>console.log('connected to port 3001'))

The HTML File

<!DOCTYPE html>
<html>
<head><title>Login Screen</title></head>
<body>
<div class = “Login-box”>
<h1>&nbsp; Login</h1>
<form action=”http://localhost:3001/user" method=”POST”><div class=”textbox”></div>
<input type=”text” name=”username” placeholder=”User name”>
<div class=”textbox”></div>
<input type=”password” name=”Password” placeholder=”Password”><br>
<button type=”submit” class=”bton”>Submit</button></br></form>
</div>
</body>
</html>

Result

React Native Developer | UI/UX Designer | Python |Tableau |AR |Arduino #IOSdeveloper