Reputation: 220
Why node.js app created as a web server via http.createServer doesn't exit after end as simple console.log() app? Is it because there is a forever while true {} cycle somewhere in http module?
Upvotes: 1
Views: 390
Reputation: 1659
Deep in the internals of Node.js there is bookkeeping being done. The number of active event listeners is being counted. Events and event-driven programming model are what make Node.js special. Events are also the life blood that keep a Node.js program alive.
A Node.js program will keep running as long as there are active event listeners present. After the last event listener has finished or otherwise terminated the Node.js program will also terminate.
For more details GO HERE
Upvotes: 2
Reputation: 24590
This is the core of node, that while waiting for new connections, to not exit. Without using loops
There are many other ways, to keep node running, without forever while. For example:
window.setTimeout(function(){},10000000)
Upvotes: 0