Express Stripe Webhook Middleware
A TypeScript library that simplifies Stripe webhook integration in Express applications by automating signature verification. Provides secure implementation and type safety with just a few lines of code.
Key Features
- Type-safe: Full TypeScript support with strict type checking
- Secure: Automatic signature verification using Stripe's SDK
- Simple API: Clean integration with Express applications
- Flexible: Custom error handlers and logging support
- Modern: Built with Vite and current dependencies
- Well-tested: Comprehensive test coverage with Vitest
Installation
npm install express-stripe-webhook-middleware stripe expressQuick Start (TypeScript)
import Stripe from 'stripe';
import express from 'express';
import { createStripeWebhookMiddleware } from 'express-stripe-webhook-middleware';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const app = express();
app.post(
'/webhook',
...createStripeWebhookMiddleware(process.env.STRIPE_WEBHOOK_SECRET!, stripe),
(req, res) => {
const event = req.body as Stripe.Event;
// Handle the event
res.json({ received: true });
}
);
app.listen(4242, () => console.log('Server running on port 4242'));Benefits
Without this package, developers must manually configure body parsing and implement signature verification logic. This middleware abstracts that complexity into a single function call, reducing boilerplate code significantly while maintaining security standards.
Tags
ExpressStripeWebhookTypeScriptnpm
License
MIT
