From node.js's server.js:
var server = http.createServer( function( argRequest, argResponse )
{
console.log("createServer: We got a hit @ " + new Date());
var filePath = ""
if( argRequest.url === '/')
{
filePath = './public/index.html'
}
else
{
filePath = './public' + argRequest.url
}
serveStatic( argResponse, filePath )
}
)
server.listen( 3000, function()
{
console.log("\nlisten: Server listening on port 3000!\n")
}
Output of the above Nodejs code:
:~/Documents/a_mean/githib$ nodemon server.js
[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
listen: Server listening on port 3000!
createServer: We got a hit @ Thu Feb 11 2021 11:27:36 GMT+0530 (... Standard Time)
./public/index.html
createServer: We got a hit @ Thu Feb 11 2021 11:27:36 GMT+0530 (... Standard Time)
./public/stylesheets/style.css
createServer: We got a hit @ Thu Feb 11 2021 11:27:36 GMT+0530 (... Standard Time)
./public/socket.io/socket.io.js
createServer: We got a hit @ Thu Feb 11 2021 11:27:36 GMT+0530 (... Standard Time)
createServer: We got a hit @ Thu Feb 11 2021 11:27:36 GMT+0530 (... Standard Time)
./public/javascripts/chat.js
./public/javascripts/chat_ui.js
The output is showing separate calls for js, css, and html files. Is this expected behaviour? Does this not mean that server is getting created repeatedly?
nodejs - http.createServer seems to call twice
This talks about 'favicon' being fetched but I don't see any such thing in my output.
What is happening here?