Answer the question
In order to leave comments, you need to log in
Why does NodeJS loop through a function twice?
In general, there is such a simple code:
const http = require('http');
function counter() {
let count = 0;
return function() {
++count;
return count;
}
}
let countAlert = counter();
http.createServer(function(request,response){
response.end(`Количество посещений сайта:${countAlert()}`);
}).listen(3000,'127.0.0.1',function() {
console.log('Подключение выполнено успешно');
})
Answer the question
In order to leave comments, you need to log in
Open your browser console and take a look.
Or log `request.url`.
Because the browser actually makes the second request for `favicon.ico`.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question