I am new to Node.js. I have implemented an \\exit
link on my site. When it is browsed, the following function is called:
function exitRequest(req, res) {
res.setHeader('Content-Type', 'text/html');
res.send("<html><body>Bye</body></html>");
console.warn('%s: Exit requested.', Date(Date.now()) );
process.exit(0);
};
The page is displayed properly and the node.js
server shuts down, but the console warning is not displayed. However, calls to console.warn
are successful in other parts of the application. I can see the messages in the output window.
What could cause this issue?
Try to delay the process termination:
console.warn('%s: Exit requested.', Date(Date.now()));
process.nextTick(function() { process.exit(0); });
Or using setTimeout
:
setTimeout(function() { process.exit(0); }, 0);
If you don't want to create a new anonymous function, you could use bind:
var exit = process.exit.bind(process, 0);
// Later...
process.nextTick(exit);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.