Node.js URL Module

      No Comments on Node.js URL Module




URL module is included by defualt in Node Js. So, when Node Js is installed , url module is installed by default.

Node Js can be included in code as below :

var url = require(“url”);

url module in NodeJs can be used to parse the url and get the query parameters.

Let’s take an example to illustrate this:

demourlmodule.js

var http = require('http');
var url = require('url');
http.createServer(function(request,response){

   var q = url.parse(request.url,true);
   var firstName = q.query.firstName;
   var lastName = q.query.lastName;

   response.write("FirstName = "+firstName + " ,LastName = "+lastName);
   response.end();

}).listen(9090);

Run this code as node demourlmodule.js

And then hit the following url in the browser
http://localhost:9090/master?firstName=Ranjan&lastName=Kumar






Leave a Reply