NodeJS http module: what is requestListener?

I am new to JS and more specifically Node. Even after reading api docs, I am confused by the fact that "requestListener" has the following method.

http.createServer([requestListener]);

A google search showed that 'requestListener' is a (n) (anonymous) function with the following signature:

function (request, response) { };

I believe that I am not reading the documents correctly, I hope someone can point me in the right direction.

+4
source share
2 answers

docs say that the method call accepts a function that will be called when a new request is received by your application. This function, as you correctly stated in your question, takes two arguments - objects requestand response.

, , . , API request response.

; :

var server = http.createServer()

server.on('request', function (req, res) {
  // Process the request here
})

, - - (.. HTTP- GET). - HTTP , - - .

+3

: , , .

, console.log(request, response) , .

. " ", , Node ( javascript) ().

0

Source: https://habr.com/ru/post/1569771/


All Articles