Skip to content

Commit c6617d7

Browse files
committed
Update README.md
1 parent 1e9d431 commit c6617d7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,6 +4189,45 @@ console.log(hashPwd); //ef5225a03e4f9cc953ab3c4dd41f5c4db7dc2e5b
41894189
<b><a href="#table-of-contents">↥ back to top</a></b>
41904190
</div>
41914191

4192+
## Q. How to gracefully shutdown Node.js Server?
4193+
4194+
The graceful shutdown of our application indicates when all of the resources it used and all of the traffic and/or data processing what it handled are closed and released properly. It means that no database connection remains open and no ongoing request fails because we stop our application.
4195+
4196+
Possible scenarios for a graceful web server shutdown:
4197+
4198+
* Handle process kill signal
4199+
* Stop new requests from client
4200+
* Close all data process
4201+
* Exit from process
4202+
4203+
**Example:**
4204+
4205+
```js
4206+
function shutdown() {
4207+
server.close(function onServerClosed(err) {
4208+
if (err) {
4209+
console.error(err);
4210+
process.exit(1);
4211+
}
4212+
4213+
closeMyResources(function onResourcesClosed(err) {
4214+
// error handling
4215+
process.exit();
4216+
});
4217+
});
4218+
}
4219+
4220+
process.on("SIGTERM", function onSigterm() {
4221+
console.info("Got SIGTERM. Graceful shutdown start", new Date().toISOString());
4222+
// start graceul shutdown here
4223+
shutdown();
4224+
});
4225+
```
4226+
4227+
<div align="right">
4228+
<b><a href="#table-of-contents">↥ back to top</a></b>
4229+
</div>
4230+
41924231
#### Q. What are the use cases for the Node.js "vm" core module?
41934232
#### Q. Explain the concept of Domain in Node.js?
41944233
#### Q. What is Node-API (N-API)?

0 commit comments

Comments
 (0)