Prerequisites
Before installing Express Zod API, make sure you have:- Node.js: Version 20.19.0, 22.12.0, or 24.0.0 or higher
- TypeScript: Version 5.1.3 or higher
- Package Manager: npm, yarn, or pnpm
Express Zod API requires TypeScript and works best with strict type checking enabled.
Install with Package Manager
Choose your preferred package manager and install Express Zod API along with its required peer dependencies:- npm
- pnpm
- yarn
Required Dependencies
Here’s what each dependency does:| Package | Purpose | Type |
|---|---|---|
express-zod-api | The main framework | Runtime |
express | Web server (v5.x) | Runtime (peer) |
zod | Schema validation (v4.x) | Runtime (peer) |
http-errors | HTTP error handling | Runtime (peer) |
@types/express | Express TypeScript types | Dev (peer) |
@types/node | Node.js TypeScript types | Dev (peer) |
@types/http-errors | HTTP errors TypeScript types | Dev (peer) |
Optional Dependencies
Depending on your needs, you may want to install these optional packages:File Uploads
For handling file uploads with multipart/form-data:- npm
- pnpm
- yarn
Response Compression
For enabling gzip/brotli compression:- npm
- pnpm
- yarn
Documentation UI
For serving interactive Swagger documentation:- npm
- pnpm
- yarn
TypeScript Configuration
Express Zod API requires specific TypeScript compiler options to work correctly. Update yourtsconfig.json:
tsconfig.json
Enable strict mode
The
strict option enables all strict type checking options. This is essential for catching type errors early and ensuring Express Zod API works as expected.Skip library checks
The
skipLibCheck option improves compilation speed by skipping type checking of declaration files. This is safe and recommended.Using CommonJS? Set
"module": "commonjs" and "moduleResolution": "node" instead. Both module systems are fully supported.Project Structure
Here’s a recommended project structure for your Express Zod API application:Verify Installation
Create a simple test file to verify everything is installed correctly:test.ts
- tsx (recommended)
- ts-node
- Compile first
The
tsx package is recommended for running TypeScript files directly during development. Install it with npm install -D tsx.Troubleshooting
Module resolution errors
Module resolution errors
If you see errors about module resolution:
- Make sure
@types/nodeis installed - Check that your
tsconfig.jsonhas correctmoduleResolutionsetting - For ES modules, ensure your
package.jsonhas"type": "module"
Peer dependency warnings
Peer dependency warnings
Express Zod API has several peer dependencies that must be installed:
express(required)zod(required)http-errors(required)typescript(required for development)
Type errors with Zod
Type errors with Zod
If you’re seeing type errors related to Zod:
- Ensure you’re using Zod v4.x (check with
npm list zod) - Make sure
strictmode is enabled intsconfig.json - Clear your TypeScript cache:
rm -rf node_modules/.cache
Express version conflicts
Express version conflicts
Express Zod API requires Express v5.x. If you have v4.x:Note that Express v5 has some breaking changes from v4. See the Express migration guide.
Next Steps
Now that you have Express Zod API installed, let’s build your first API:Quickstart Guide
Create a working API in under 5 minutes