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 checked.
Awesome! Now we're loaded up and ready to go 🚀.
3. Using Cursor AI for Migration Assistance
One of the powerful features of Cursor is its ability to help with code migration. Here's how to use it:
Open your Express.js file in Cursor along with our newly created Encore.ts project.
Finally, this is how your Cursor setup should look like:
Use the Chat Interface (Cmd + L), select Composer and type "Convert this Express.js code to Encore.ts" by giving the whole context of the files you have open.
Cursor will analyze your code and suggest the appropriate Encore.ts structure, handling:
- Route conversions
- Type definitions
- Validation logic
- Error handling
Once Cursor gives you a proposal, click Accept
on all the changes and save your files.
Keep in mind: Using AI generation is not deterministic, so results will not always look exactly the same. With Cursor's understanding Encore.ts, it will normally do a really good job of migrating an Express app to Encore.
Testing Our Migrated App
We're off to a great start and we have our first API written with Encore.ts, but we haven't tested it yet. So let's test it out!
Run your Encore application:
encore run
This will:
- Start your application
- Set up necessary infrastructure
- Provide a local development dashboard
- Generate API documentation automatically
Now open the local development dashboard: localhost:9400
In the dashboard, you can test the endpoint from the API explorer and see the response. You can even look at a complete trace of the request and everything it did.
Deploying our Encore.ts Application
So we have written the code, tested it and now we want to deploy it.
There are two ways to do so with Encore. You can either deploy by generating a docker image for your app using:
encore build docker MY-IMAGE:TAG
This will compile your application using the host machine and then produce a Docker image containing the compiled application. You can now deploy this anywhere you like. Learn more in the self-host docs.
Or with a free Encore Cloud account, you can use Encore Cloud to automate deployment. You only need to git push:
git add -A .
git commit -m 'Initial commit'
git push encore
After pushing your code, Encore Cloud will:
- Build and test your app
- Provision the needed infrastructure
- Deploy your application to a staging environment
You'll receive a URL to track your deployment progress in the Encore Cloud dashboard (something like https://app.encore.cloud/$APP_ID/deploys/...
).
From there, you can:
- View production traces
- Connect your cloud account (so you can automate deployments to you AWS and GCP)
- Integrate with GitHub
- Monitor your application
- And much more!
Conclusion
In this blog, we saw how we can use Cursor AI to migrate our Express.js application to Encore.ts. We also saw how we can test our application and deploy it to Encore Cloud.
I hope you enjoyed this blog post! You can try it out for yourself and let me know what you think.
Top comments (0)