Node.js requestListener() Function
Example
The requestListener function is the function that is executed each time the server gets a request:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello
World!');
res.end();
}).listen(8080);
Run example »
Definition and Usage
The requestListener is a function that is called each time the server gets a request.
The requestListener function is passed as a parameter to the http.createServer() method.
The requestListener function handles requests from the user, and also the response back to the user
Syntax
function (request, response) {
}
Parameter Values
Parameter | Description |
---|---|
request | The first parameter, the Request object, represents an IncomingMessage object. |
response | The second parameter represents a ServerResponse object, which has methods for handling the response stream back to the user |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.