NPM Package: @flowglad/express
Overview
The Express SDK provides middleware and route handlers for integrating Flowglad into your Express.js applications. It works seamlessly with the Flowglad Server SDK to handle billing operations.Installation
Quick Start
1. Set Up Environment Variables
.env
2. Create Flowglad Server Factory Function
src/utils/flowglad.ts
3. Add Routes to Your Express App
Key Features
- Express Router: Pre-configured router for easy mounting
- Route Handler: Flexible handler for custom routing
- Request Context: Automatic customer context from requests
- Error Handling: Built-in error handling for billing operations
- Type Safety: Full TypeScript support
API Reference
createFlowgladExpressRouter
Creates an Express router with all Flowglad routes pre-configured.Parameters
Returns
Router- An Express router instance
Example
createExpressRouteHandler
Creates a route handler function for custom routing setups.Parameters
Returns
RequestHandler- An Express request handler
Example
Integration with Authentication
Passport.js Example
src/utils/flowglad.ts
JWT Auth Example
src/utils/flowglad.ts
Session-Based Auth Example
src/utils/flowglad.ts
Complete Example
Here’s a full Express application with Flowglad integration:src/index.ts