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.
The following options are supported when generating an Express backend:
See TypeScript Node.js SDK Configuration options: useBrandedStringAliases.
See TypeScript Node.js SDK Configuration options: treatUnknownAsAny.
See TypeScript Node.js SDK Configuration options: noSerdeLayer.
See TypeScript Node.js SDK Configuration options: outputSourceFiles.
By default, the generated
register() will require an implementatiion for every
service defined in your Fern Definition.
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.
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.
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.
The generated TypeScript code has the following dependencies:
If you are packaging your code manually, make sure to include these dependencies in your