Express Integration
Block disposable emails in your Express app with a simple middleware or inline check.
Inline check
The quickest way — add a check directly in your route handler:
server.tstypescript
import express from 'express';
import { isDisposable } from '@isdisposable/js';
const app = express();
app.use(express.json());
app.post('/signup', (req, res) => {
const { email } = req.body;
if (isDisposable(email)) {
return res.status(400).json({
error: 'Please use a real email address.'
});
}
// Continue with signup...
res.json({ success: true });
});
app.listen(3000);Reusable middleware
Create a middleware you can apply to any route that accepts emails:
middleware/block-disposable.tstypescript
import { isDisposable } from '@isdisposable/js';
import { Request, Response, NextFunction } from 'express';
interface Options {
emailField?: string; // which field in req.body (default: 'email')
errorMessage?: string; // custom error message
errorStatus?: number; // HTTP status code (default: 400)
}
export function blockDisposable(options: Options = {}) {
const {
emailField = 'email',
errorMessage = 'Please use a real email address.',
errorStatus = 400,
} = options;
return (req: Request, res: Response, next: NextFunction) => {
const email = req.body?.[emailField];
if (!email) return next();
if (isDisposable(email)) {
return res.status(errorStatus).json({ error: errorMessage });
}
next();
};
}server.tstypescript
import express from 'express';
import { blockDisposable } from './middleware/block-disposable';
const app = express();
app.use(express.json());
// Apply to specific routes
app.post('/signup', blockDisposable(), (req, res) => {
res.json({ success: true });
});
app.post('/invite', blockDisposable({ emailField: 'inviteeEmail' }), (req, res) => {
res.json({ invited: true });
});
// Or apply globally to all POST routes
// app.use(blockDisposable());With Pro API
For real-time detection with risk scoring:
server.tstypescript
import express from 'express';
import { createIsDisposable } from '@isdisposable/js';
const checker = createIsDisposable({
apiKey: process.env.ISDISPOSABLE_API_KEY!,
});
const app = express();
app.use(express.json());
app.post('/signup', async (req, res) => {
const { email } = req.body;
const result = await checker.check(email);
if (result.disposable) {
return res.status(400).json({
error: 'Please use a real email address.',
score: result.score,
reason: result.reason,
});
}
// result.score < 50 — safe to proceed
res.json({ success: true });
});Score threshold
By default, emails with a score of 50 or higher are considered disposable. You can use a custom threshold — for example, only block emails with
score >= 70 for a stricter filter.Fastify
Works the same way in Fastify:
server.tstypescript
import Fastify from 'fastify';
import { isDisposable } from '@isdisposable/js';
const app = Fastify();
app.post('/signup', async (request, reply) => {
const { email } = request.body as { email: string };
if (isDisposable(email)) {
return reply.status(400).send({
error: 'Please use a real email address.'
});
}
return { success: true };
});