I am beginner to web development. I created a simple form using HTML and CSS, which contained three widgets i.e. name, email and phone. Now I want to send data to the server and store in it using NodeJS. What should I do?
Here is my HTML file.
<!DOCTYPE html>
<html>
<head>
<Meta charset = "uft-8">
<title> Singing up for The Event </title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<form action = "/registration-form" method = "post">
<div>
<label for="name"> Name: </label>
<input type="text" id="name" name="user_name">
</div>
<div>
<label for="mail"> E-mail: </label>
<input type="email" id="mail" name="user_mail">
</div>
<div>
<label for="phone"> Phone:</label>
<input type="number" id="phone" name="user_phone"></input>
</div>
<div class="button">
<button type="submit">Register!</button>
</div>
<div class="button">
<button type="Reset">Reset!</button>
</div>
</form>
</body>
</html>
Here is my server.js file.
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var port = process.env.PORT || 63342;
//POST
app.post('/api/users', function(req, res) {
var user_name = req.body.user_name;
var user_mail = req.body.user_mail;
var user_phone = req.body.user_phone;
res.send(user_name + ' ' + user_mail + ' ' + user_phone);
})
//starting the server
app.listen(port);
console.log("Running at port 63342...");
I am not sure what to do next. How to check if the request was successful and is there any way to make a request via opening and filling the HTML form directly.