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.
Related Tools & Apps
stripe-pwa-elements
Stripe payment Web Components that work with any web framework. Integrate card payments, Apple Pay, Google Pay, Payment Element and more using simple HTML tags. Built on Stencil.js for framework-agnostic usage, with PWA and Capacitor support.
stripe-search-ql
A TypeScript query builder for constructing Stripe Search API queries with type safety. Eliminate bugs caused by hand-written query strings using a fluent, chainable API that improves developer productivity.
cdk-construct-stripe-events-to-sns
I have developed a CDK Construct library for receiving Stripe payment events via AWS EventBridge and sending notifications to an SNS topic. This design reduces costs and latency by sending notifications directly from EventBridge to SNS without using Lambda functions.
