After starting the node.js server, does it have to be refreshed before the terminal can have output?

var http = require("http")
var server = http.createServer(function(req,res){
    console.log("hello")
    console.log(2222)
    res.setHeader("Content-Type","text/html","charset=gbk")
    res.write("<h1>jirengu</h1>")
    console.log(__dirname)
    
    res.end()
})
server.listen(8080)

it takes a refresh to output hello 2222 on the terminal. Why?

Feb.27,2021

there must be output only when you visit 8080.


every time you visit the web page code you are listening to, the code


console.log ("hello") is not executed by Synchronize. It will be executed only if the corresponding event is triggered, such as a request.

Menu