shantanu
shantanu

Reputation: 2008

request.url is not giving complete url in nodejs

I am running the following code snippet from the node js beginner book.

var http = require("http");
var url = require("url");


function onRequest(request, response) {
    console.log("request url issss " + request.url);
    var pathName = url.parse(request.url).pathName;
    console.log("Request for " + pathName + " received");

    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello Worldd");
    response.end();

}

http.createServer(onRequest).listen(8888);  

console.log("Server has started11.");

Now while hitting http://localhost:8888/start in the browser, i am getting request.url is start only instead of full url. Hence path name is coming undefined.

Following is the console out put

Server has started11.
request url issss /start/
Request for undefined received

Thanks,
Shantanu

Upvotes: 0

Views: 682

Answers (1)

mscdex
mscdex

Reputation: 106746

It's pathname with the n lowercased.

Also, request.url does not contain the fully qualified URL, it only contains the requested URL that the client sends.

Upvotes: 1

Related Questions