1. Tutorials
  2. TypeScript Express

This guide uses an example API for IMDb that introduces you to using Fern. We’ll generate a TypeScript Express server and a Postman collection to implement and test our API.

👀 Sneak peak:

Here’s what your repo will look like after completing the tutorial.

Step 0: Prerequisites

Have a question?

We’re here to help! Reach out in Discord.

Step 1: Set up

Create a new folder for this tutorial and cd into it. Let’s create a new npm project.

This will set us up for a new TypeScript Express backend repo. We’ll also install fern:

Step 2: Initialize

In the root of your backend repo, run:

When it asks you for the name of your organization, enter imdb.

This will add the following:

Step 3: Add TypeScript code generator

When adding a generator, Fern defaults to the SDK (aka client). We’ll see this by running:

This will add:

/fern/api/generators.yml

For this tutorial, we want to generate a TypeScript Express server, so we’ll change this to:

/fern/api/generators.yml

Have a question?

We’re here to help! Reach out in Discord.

Step 4: Run the generator

Next we’ll invoke the TypeScript server code generator by running:

After a few seconds of processing, you’ll see a message in your terminal. Here’s a screenshot after the code generator ran successfully:

Successful code generation

Step 5: Install the generated package

Create a new file .npmrc at the root of our project and add the following:

This tells npm the location of your generated package. By default, packages are published to a private registry.

Next we’ll install the package by running npm install @imdb-fern/api-server@0.0.3. This will add the dependency:

/package.json

Step 6: Implement the server

Create a new file server.ts at the root of our project. This will be the server which serves the API.

Copy and paste the following:

/server.ts

Step 7: Run the server

In the terminal, you should see Listening for requests... Great, our server is running!

Step 8: Add the Postman generator

Open a new terminal window and run:

In the api/ folder you’ll see generated-postman.json was recently created.

Step 9: Hit the server from postman

Open Postman. Click File -> Import and navigate to api/generated-postman.json. You should now see a collection called api.

Click the createMovie endpoint and then click Send. You should get iron-man-3 back from your server.

createMovie-postman

Select the getMovie endpoint and hit Send. As expected, we get a 404 response back.

getMovie-postman

Step 10: Celebrate 🎉

You’ve successfully implemented a IMDb TypeScript Express server using Fern. You’re invited to join our Discord.