Source code
A starter repo for Express + React, using Fern
Latest version: 0.9.7
The Express generator generates types and networking logic for your Express server. This saves you time and adds compile-time safety by guaranteeing that you are serving the exact API that you specified in your API Definition.
Available on the open source plan.
What Fern generates
- TypeScript interfaces for your API types
- Exceptions that you can throw for non-200 responses
- Interfaces for you to define your business logic
- All the networking/HTTP logic to call your API
Adding the Express generator
Make sure to enable allowSyntheticDefaultImports
in your tsconfig.json
when using this generator.
Demo video
Express configurations
The following options are supported when generating an Express backend:
useBrandedStringAliases
See TypeScript Node.js SDK Configuration options: useBrandedStringAliases.
treatUnknownAsAny
See TypeScript Node.js SDK Configuration options: treatUnknownAsAny.
noSerdeLayer
See TypeScript Node.js SDK Configuration options: noSerdeLayer.
outputSourceFiles
See TypeScript Node.js SDK Configuration options: outputSourceFiles.
areImplementationsOptional
Type: boolean
Default: false
By default, the generated register()
will require an implementatiion for every
service defined in your Fern Definition.
If areImplementationsOptional
is enabled, then register()
won’t require any
implementations. Note that this is mildly dangerous: if you forget to include
an implementation, then your server behavior may drift from your docs and clients.
✨ doNotHandleUnrecognizedErrors
Type: boolean
Default: false
By default, if you throw a non-Fern error in your endpoint handler, it will be caught by generated code and a 500
response will be returned. No details from the error will be leaked to the client.
If doNotHandleUnrecognizedErrors
is enabled and you throw a non-Fern error, the error will be caught and passed on with next(error)
. It’s your responsibility to set up error-catching middleware that handles the error and returns a response to the client.
Dependencies
The generated TypeScript code has the following dependencies:
If you are packaging your code manually, make sure to include these dependencies in your package.json
.