0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.