DEV Community

Cover image for How to make your Express.js APIs 9x faster with Encore.ts

How to make your Express.js APIs 9x faster with Encore.ts

Simon Johansson on September 10, 2024

Encore.ts is Open Source backend framework for TypeScript. This guide walks you through how to migrate an Express.js app to Encore.ts to gain type-...
Collapse
 
jhonleo02 profile image
Jhonleo • Edited

To make your Express.js APIs 9x faster, migrate to Encore.ts, an open-source TypeScript framework built for high performance. Encore.ts uses a multi-threaded, asynchronous runtime in Rust, handling I/O efficiently. It has no external npm dependencies and includes built-in features for production-ready backends, ensuring a smoother and faster API experience. Fore information Discover it

Collapse
 
herberthk profile image
herberthk

Thanks for sharing

Collapse
 
serhiyandryeyev profile image
Serhiy

comprehensive guide! thanks!

Collapse
 
simonjohansson profile image
Simon Johansson

Glad you liked it šŸ‘

Collapse
 
tauksun profile image
tauksun

Encore.ts looks great.

Few questions :

If it has a separate runtime written in Rust with multi-threading approach,
then it is not using Nodejs.

Isn't it like comparing server written in Rust/C/Go with Nodejs ?

Does it also uses it own thing to transpile JavaScript other than JIT used by Nodejs ( Ignition & Turbofan ) ?

Collapse
 
simonjohansson profile image
Simon Johansson

Thanks for the questions!

If it has a separate runtime written in Rust with multi-threading approach, then it is not using Nodejs.

Well, its a bit of both. The Encore Runtime handles all I/O like accepting and processing incoming HTTP requests. This runs as a completely independent event loop that utilizes as many threads as the underlying hardware supports (written in Rust).

Once the request has been fully processed and decoded, it gets handed over to the Node.js event-loop, and then takes the response from the API handler and writes it back to the client.

So you can write your business logic in TypeScript but you get a lot of the performance benefits from Rust.

Isn't it like comparing server written in Rust/C/Go with Nodejs?

I think the comparison is fair because you still write TypeScript as usual, using the NPM libs that you are use to. The Rust performance boost happens under the hood and is not affecting the business logic of your app.

Does it also uses it own thing to transpile JavaScript other than JIT used by Nodejs ( Ignition & Turbofan ) ?

Encore leverages static code analysis to parse your TypeScript code and picks up the API schemas and infrastructure you have defined. For the actual transpiling, Encore relies on Node for that. Transpiling TypeScript to JavaScript is currently done with esbuild.

Collapse
 
ricardogesteves profile image
Ricardo Esteves

Great article, thank you for sharing it. Looks like an awesome solution. Will definitely try it out.

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

šŸ™Œ

Collapse
 
greenflag31 profile image
Green

Honestly, the API does not look really good. Putting everything in an api(...) function :/
Plus there are no repo on npm to download it, it looks like an Desktop application installation.
The API does not look really scalable too (see file upload exemple)

Collapse
 
abdul_saleem_890e0becdf2e profile image
Abdul saleem

What about server resources consumption like CPU and memory?

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Hey that's a great question. Since Encore.ts enables higher throughput, it means you can serve the same number of users with fewer servers or, conversely, you can serve more users with the same number of servers... which directly corresponds to lower costs.

Collapse
 
abdul_saleem_890e0becdf2e profile image
Abdul saleem

Because it is not been highlighted in anywhere in website or any thread.
Thanks for your reply and expecting more proof in upcoming articles.

Collapse
 
chandra_pantachhetri profile image
Chandra Panta Chhetri

Very interesting, the requests/sec diagram caught my attention. Do you have any example repositories that use encore.ts? I'd love to check them out

Collapse
 
simonjohansson profile image
Simon Johansson

Cool! Here is our example repo with a bunch of different examples:
github.com/encoredev/examples/tree...

Collapse
 
talhaahsan profile image
Talha Ahsan

I want to ask how to implement middleware in Encore.ts. I created a small app in Express, but when I tried to implement it in Encore.ts, I couldn't figure out where to write the middleware.

Collapse
 
amannegi profile image
Aman Negi

I delved into it, and I found it interesting. However stuck on finding information on how to connect other Database(MongoDB). I also couldn't find a central place to initialize my DB globally once.