Saborter Server a lightweight Node.js library that automatically cancels server-side operations when the client aborts a request. Built on the standard AbortController API, it seamlessly with Express framework and allows you to stop unnecessary database queries, file writes, or external API calls, saving server resources and improving scalability. Fully tree‑shakeable – only the code you actually use ends up in your bundle.
The documentation is divided into several sections:
npm install saborter @saborter/server
# or
yarn add saborter @saborter/serverimport express from 'express';
import { isAbortError } from 'saborter/lib';
import { initRequestInterrupts, getAbortSignal } from '@saborter/server/express';
const app = express();
const port = process.env.PORT || 3000;
initRequestInterrupts(app);
app.use(express.json());
app.get('/', async (req, res) => {
try {
const result = await longRunningOperation(getAbortSignal(req));
res.json(result);
} catch (error) {
if (isAbortError(error)) {
return res.status(499).send();
}
res.status(500).send();
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});If you don't want to use the getAbortSignal function, you can declare the Request interface:
declare namespace Express {
interface Request {
signal?: AbortSignal;
}
}After the declaration, you can directly retrieve the signal from the request:
const result = await longRunningOperation(req.signal);
res.json(result);MIT License - see LICENSE for details.
