Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Is Your Node Process Too Busy?

[![Build Status](https://secure.travis-ci.org/lloyd/node-toobusy.png)](http://travis-ci.org/lloyd/node-toobusy)
[![Build Status](https://secure.travis-ci.org/lloyd/node-toobusy.svg)](http://travis-ci.org/lloyd/node-toobusy)

What happens when your service is overwhelmed with traffic?
Your server can do one of two things:
Expand All @@ -23,38 +23,38 @@ and continue serving as many requests as possible.

## installation

```
npm install toobusy
```bash
npm install toobusy --save
```


## usage

```javascript
var toobusy = require('toobusy'),
```js
const toobusy = require('toobusy'),
express = require('express');
var app = express();

const app = express();

// middleware which blocks requests when we're too busy
app.use(function(req, res, next) {
app.use((req, res, next) => {
if (toobusy()) {
res.send(503, "I'm busy right now, sorry.");
} else {
next();
}
});

app.get('/', function(req, res) {
app.get('/', (req, res) => {
// processing the request requires some work!
var i = 0;
let i = 0;
while (i < 1e5) i++;
res.send("I counted to " + i);
});

var server = app.listen(3000);
const server = app.listen(3000);

process.on('SIGINT', function() {
process.on('SIGINT', () => {
server.close();
// calling .shutdown allows your process to exit normally
toobusy.shutdown();
Expand Down