I have a general question about Node Js response, and was hoping someone can explain what is actually going on when I do lets say res.WriteHead("blah blah").
So from what I understand in my html and javascript I make a request for a route. I check the request of the route and lets say its a get method. I do write head which will write the head of a http response. What will happen if I send res.write("some text");.
What i'm asking is can you explain the process and whats really going on with the communication between the client and server.
I'm a little confused on the response is this one message being sent back or is this like a stream.
Answers with as much explanation on the entire process would be greatly appreciated.
Some sample code of what im talking about. Please note im using NodeJS
// load http module var http = require('http');
//create the server var server = http.createServer(handleRequest);
//start the server server.listen(2000);
//request handler function function handleRequest(req, res) {
console.log(req.method+" request for "+req.url);
// content header
res.writeHead(200, {'content-type': 'text/plain'});
res.write("ohai!\n");
// write message body and send
res.end("Hello, World!"); };
Aucun commentaire:
Enregistrer un commentaire