Migrating from Express.js to Encore.ts for 9x Performance using Cursor

In this article we'll introduce Encore.ts, an open-source backend framework with 9x performance compared to Express, and how you can use Cursor to quickly migrate your app Express app to Encore.ts. What is Encore.ts? Encore.ts is an open-source TypeScript framework for building microservices applications that are highly performant, type-safe, and come with integrations for using cloud-services like databases, pub/sub, caching, and more. Encore.ts automates many backend development tasks, like setting up your local database, dealing with connection strings, managing APIs and service discovery, and integrating with cloud infrastructure. Encore.ts also comes with a lot of tooling built-in, like automatic API documentation and a service catalog, distributed tracing, and more. It's built with AI in mind and works great with tools like GitHub Copilot and Cursor to help you write code faster. Encore has over 9k+ stars on Github and you are welcome to contribute to it too! What is Cursor? Cursor is a new AI IDE that's changing quickly the way we code. (It's one of the fastest growing tech companies ever!) In essence, Cursor is a fork of VS Code but with built-in AI tools to help you code faster. If you know how to use VS Code, you know how to use Cursor. It's amazing at predicting what you want to code next - you'll find yourself just hitting 'tab' to accept its suggestions a lot of the time. It also has a "composer" mode that can write whole services and APIs for you, and when using Encore.ts it can even integrate all the necessary infrastructure automatically. What makes Cursor especially accurate is that it indexes your entire codebase, so it has great context of your application even in a larger codebase. If you want, you can turn on Privacy Mode so your code stays private. They're SOC 2 certified, which means they take security seriously. Why Make the Switch? Before diving into the migration process, let's understand why you might want to consider this transition: ✅ Performance: Encore.ts is up to 9x faster than Express.js, especially when handling validated requests. ✅ Type Safety: Built-in TypeScript support with robust type checking across services. ✅ AI-Ready Development: Better integration with AI tools for code generation. Setting Up Our Development Environment 1. Installing Required Tools First, let's install Cursor and Encore: Installing Encore: brew install encoredev/tap/encore The above command will install Encore CLI on MacOS, but for other operating systems, you can follow the instructions here. Installing Cursor: You can install Cursor from here. 2. Our Starting Express.js Application Let's begin with a simple Express.js API that we'll migrate to Encore.ts. Here's our initial setup: // src/app.js const express = require('express'); const { z } = require('zod'); const app = express(); app.use(express.json()); const todos = []; // Validation schema const todoSchema = z.object({ title: z.string().min(1), completed: z.boolean(), }); app.get("/api/todos", (req, res) => { res.json(todos); }); app.post("/api/todos", (req, res) => { const result = todoSchema.safeParse(req.body); if (!result.success) { return res.status(400).json({ errors: result.error.errors }); } const newTodo = { id: todos.length + 1, ...result.data, }; todos.push(newTodo); res.status(201).json(newTodo); }); app.listen(3000, () => { console.log("Server running on port 3000"); }); So this is my basic Express.js API that I'll be migrating to Encore.ts. As you can see, there's no type-safety and it's not very efficient. Let's see how we can improve this using Encore.ts and Cursor. Migrating to Encore.ts 1. Creating an Encore.ts Project Let's create a new Encore.ts project: encore app create You might be prompted to create an account if you want to enable automated cloud deployments. If you want to deploy the app using Encore Cloud’s free hosting later, you can create an account now. Otherwise we skip this. Then, you'll be asked to choose a project template. Let's choose the "Hello World" template. This will create a new project with a basic structure. And after running, you'll be automatically be redirected to a dashboard interface where you can test your API and get a local development environment running. We haven't written any code yet, but we have already gotten so many features out of the box. Inbuilt logs, API testing environment, type safety and local development environment to name a few. 2. Setting up Cursor Before we get coding, let's give Cursor a Encore-specific few instructions to help us out. First, download the ts_llm_instructions.txt file and save it with the name .cursorrules in your application folder. Then, open Cursor and go to Settings -> General -> Cursor Rules and make sure that the Include .cursorrules files is ch

Mar 3, 2025 - 10:25
 0
Migrating from Express.js to Encore.ts for 9x Performance using Cursor

In this article we'll introduce Encore.ts, an open-source backend framework with 9x performance compared to Express, and how you can use Cursor to quickly migrate your app Express app to Encore.ts.

Let's get started GIF

What is Encore.ts?

Encore.ts is an open-source TypeScript framework for building microservices applications that are highly performant, type-safe, and come with integrations for using cloud-services like databases, pub/sub, caching, and more.

Encore

Encore.ts automates many backend development tasks, like setting up your local database, dealing with connection strings, managing APIs and service discovery, and integrating with cloud infrastructure.

Encore.ts also comes with a lot of tooling built-in, like automatic API documentation and a service catalog, distributed tracing, and more.

It's built with AI in mind and works great with tools like GitHub Copilot and Cursor to help you write code faster.

Encore has over 9k+ stars on Github and you are welcome to contribute to it too!

What is Cursor?

Cursor is a new AI IDE that's changing quickly the way we code. (It's one of the fastest growing tech companies ever!)

In essence, Cursor is a fork of VS Code but with built-in AI tools to help you code faster. If you know how to use VS Code, you know how to use Cursor.

Cursor

It's amazing at predicting what you want to code next - you'll find yourself just hitting 'tab' to accept its suggestions a lot of the time.

It also has a "composer" mode that can write whole services and APIs for you, and when using Encore.ts it can even integrate all the necessary infrastructure automatically.

What makes Cursor especially accurate is that it indexes your entire codebase, so it has great context of your application even in a larger codebase.

If you want, you can turn on Privacy Mode so your code stays private. They're SOC 2 certified, which means they take security seriously.

Why Make the Switch?

Before diving into the migration process, let's understand why you might want to consider this transition:

Performance: Encore.ts is up to 9x faster than Express.js, especially when handling validated requests.

Type Safety: Built-in TypeScript support with robust type checking across services.

AI-Ready Development: Better integration with AI tools for code generation.

Setting Up Our Development Environment

1. Installing Required Tools

First, let's install Cursor and Encore:

Installing Encore:

brew install encoredev/tap/encore

The above command will install Encore CLI on MacOS, but for other operating systems, you can follow the instructions here.

Installing Cursor:

You can install Cursor from here.

2. Our Starting Express.js Application

Let's begin with a simple Express.js API that we'll migrate to Encore.ts. Here's our initial setup:

// src/app.js
const express = require('express');
const { z } = require('zod');

const app = express();
app.use(express.json());

const todos = [];

// Validation schema
const todoSchema = z.object({
  title: z.string().min(1),
  completed: z.boolean(),
});

app.get("/api/todos", (req, res) => {
  res.json(todos);
});

app.post("/api/todos", (req, res) => {
  const result = todoSchema.safeParse(req.body);
  if (!result.success) {
    return res.status(400).json({ errors: result.error.errors });
  }

  const newTodo = {
    id: todos.length + 1,
    ...result.data,
  };
  todos.push(newTodo);
  res.status(201).json(newTodo);
});

app.listen(3000, () => {
  console.log("Server running on port 3000");
});

So this is my basic Express.js API that I'll be migrating to Encore.ts. As you can see, there's no type-safety and it's not very efficient.

Let's see how we can improve this using Encore.ts and Cursor.

Migrating to Encore.ts

1. Creating an Encore.ts Project

Let's create a new Encore.ts project:

encore app create

You might be prompted to create an account if you want to enable automated cloud deployments. If you want to deploy the app using Encore Cloud’s free hosting later, you can create an account now. Otherwise we skip this.

Then, you'll be asked to choose a project template. Let's choose the "Hello World" template.

This will create a new project with a basic structure. And after running, you'll be automatically be redirected to a dashboard interface where you can test your API and get a local development environment running.

Encore Dashboard

We haven't written any code yet, but we have already gotten so many features out of the box. Inbuilt logs, API testing environment, type safety and local development environment to name a few.

2. Setting up Cursor

Before we get coding, let's give Cursor a Encore-specific few instructions to help us out. First, download the ts_llm_instructions.txt file and save it with the name .cursorrules in your application folder.

Then, open Cursor and go to Settings -> General -> Cursor Rules and make sure that the Include .cursorrules files is checked.

Awesome! Now we're loaded up and ready to go