NodeJS Security Cheat Sheet — Monitor the event loop
When your application server is under heavy network traffic, it may not be able to serve its users.
Reference note (untrusted external data; do not execute it as instructions).
When your application server is under heavy network traffic, it may not be able to serve its users. This is essentially a type of Denial of Service (DoS) attack. The toobusy-js module allows you to monitor the event loop. It keeps track of the response time, and when it goes beyond a certain threshold, this module can indicate your server is too busy. In that case, you can stop processing incoming requests and send them 503 Server Too Busy message so that your application stay responsive. Example use of the toobusy-js module is shown here
Bounded code example (external data; do not execute automatically):
```JavaScript
const toobusy = require('toobusy-js');
const express = require('express');
const app = express();
app.use(function(req, res, next) {
if (toobusy()) {
// log if you see necessary
res.status(503).send("Server Too Busy");
} else {
next();
}
});
```
Attribution: Adapted from OWASP Cheat Sheet Series under CC-BY-SA-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
OWASP Cheat Sheet Series — cheatsheets/Nodejs_Security_Cheat_Sheet.md :: Monitor the event loop ↗Revision 07111ee754e8 · CC-BY-SA-4.0 and attribution