Node.js express Module

Node.js express Module

Node.js express Module is used to create back end web application framework for building RESTful APIs with Node.js

Installing and using Express

NPM - Node package manager is used to install Express module. 

Use below command in terminal to install Express module in node.js

Express module is used to send HTTP request by post, put, get and delete and recieve HTTP response.

 

$ npm install express --save

You can create a simple “Hello Nodejs tutorials” application as below example.

Save this program in file named server.js and run it using command as below.

$ node server.js

 

 

 

Example :

var express=require('express');

var app=express();

app.get('/',function(req,res)
{
res.send('Hello Nodejs tutorials!');
});

// Sends POST request
app.post('/', function (req, res) {
console.log("Received a POST request for the homepage");
res.send('Hello, POST Method');
})

// Sends DELETE request for the delete_record page.
app.delete('/delete_record', function (req, res) {
console.log("Received a DELETE request for delete_record");
res.send('Hello, DELETE Method');
})


var server=app.listen(5000,function() {
console.log('Server running at port 5000')
});

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

51248