The code below is a simple Node.js web server that responds to a request when the URL is matched.
Researching online about node.js it is stated that once you start your script (node index.js
) callbacks will be placed in their appropriate phase, then after your script is parsed the node process will enter the Event Loop and execute appropriate callbacks specific to a phase. Node will exit if there are no more callbacks to be executed.
So my question is if the request handler is run the first time when I visit the home page "/"
OR Hello Page "/hello
", how come node is still running even after subsequent requests.
const http = require('http');
const server = http.createServer((req,res) => {
if(req.url === "/") {
res.end("Home Page")
}
else if(req.url === "/hello") {
res.end("Hello Page")
}
else {
res.end("Page Not Found")
}
})
server.listen(5000)
I expect that once the Request Handler is executed it should be removed from whichever Phase it has been put into, hence node should exit. So what is keeping the Node program from exiting?
I'm trying to take an array of objects and, without mutating the original array, rename a specific key in each object. I've created a new variable and assigned it to the result of using 'map' on my ...
I'm trying to take an array of objects and, without mutating the original array, rename a specific key in each object. I've created a new variable and assigned it to the result of using 'map' on my ...
I tried finding the solution to my problem, but couldnt find it, and was looking for some "best practice examples". I have a nodejs express application and my functions are split in files. For example ...
I tried finding the solution to my problem, but couldnt find it, and was looking for some "best practice examples". I have a nodejs express application and my functions are split in files. For example ...
I often use this strategy to my java code in order to make a Collection read only for the outside world, but avoid big/often clonings: public abstract class MyClass { List<Long> myIds; ...
I often use this strategy to my java code in order to make a Collection read only for the outside world, but avoid big/often clonings: public abstract class MyClass { List<Long> myIds; ...
I'm trying to pass a string parameter using the link. but it seems that computed or methods property cannot return the parameter value. The whole component stops rendering when I use computed property....
I'm trying to pass a string parameter using the link. but it seems that computed or methods property cannot return the parameter value. The whole component stops rendering when I use computed property....