Skip to main content

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:

Required Dependencies

Here’s what each dependency does:
Express Zod API requires Express v5 and Zod v4. If you’re using older versions, you’ll need to upgrade or use an older version of Express Zod API (v23.x for Zod 3.x).

Optional Dependencies

Depending on your needs, you may want to install these optional packages:

File Uploads

For handling file uploads with multipart/form-data:

Response Compression

For enabling gzip/brotli compression:

Documentation UI

For serving interactive Swagger documentation:

TypeScript Configuration

Express Zod API requires specific TypeScript compiler options to work correctly. Update your tsconfig.json:
tsconfig.json
1

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.
2

Skip library checks

The skipLibCheck option improves compilation speed by skipping type checking of declaration files. This is safe and recommended.
3

Configure module system

Express Zod API works with both CommonJS and ES modules. The example above uses ES modules ("module": "ESNext"), which is recommended for new projects.
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
Run it with:
If you see “Server running on http://localhost:8080”, you’re all set!
The tsx package is recommended for running TypeScript files directly during development. Install it with npm install -D tsx.

Troubleshooting

If you see errors about module resolution:
  1. Make sure @types/node is installed
  2. Check that your tsconfig.json has correct moduleResolution setting
  3. For ES modules, ensure your package.json has "type": "module"
Express Zod API has several peer dependencies that must be installed:
  • express (required)
  • zod (required)
  • http-errors (required)
  • typescript (required for development)
Some peer dependencies are optional and only needed if you use specific features (compression, file uploads, etc.).
If you’re seeing type errors related to Zod:
  1. Ensure you’re using Zod v4.x (check with npm list zod)
  2. Make sure strict mode is enabled in tsconfig.json
  3. Clear your TypeScript cache: rm -rf node_modules/.cache
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