Demonstration of POST method using NodeJS and ExpressJS

Rajnilari2015
Posted by Rajnilari2015 under Node.js category on | Points: 40 | Views : 550
In the below code, we will find an example that demonstrates the use of POST method using NodeJS and ExpressJS

//add the express module
var express = require('express');

//create an instance of express module
var app = express();

//prepare the Employee data source/model
var employees =
[
{
"EmployeeID" :1 ,
"EmployeeName" : "RNA Team",
"Salary" : "200000",
"Address" : "Bangalore"
},
{
"EmployeeID" :2 ,
"EmployeeName" : "Mahesh Samabesh",
"Salary" : "100000",
"Address" : "Hydrabad"
},
{
"EmployeeID" :3 ,
"EmployeeName" : "Rui Figo",
"Salary" : "50000",
"Address" : "Dallas"
},
{
"EmployeeID" :4 ,
"EmployeeName" : "Indradev Jana",
"Salary" : "456789",
"Address" : "Los Angles"
},
{
"EmployeeID" :5 ,
"EmployeeName" : "Suresh Shailesh",
"Salary" : "1234567",
"Address" : "Patna"
}
];

//insert a new employee record

//create a new employee record
var newEmployee = [
{
"EmployeeID" :6 ,
"EmployeeName" : "Arina Biswas",
"Salary" : "555555",
"Address" : "Kolkata"
}
];

//Get the Employee records
app.get('/', function (req, res) {
res.send(employees);
});

//run the server
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;

console.log('Server started and is listening at :> http://%s:%s', host, port);
});

Comments or Responses

Login to post response