Elysia

Elysia
Elysia

Un cousin d'Express sous Bun

gouz.dev

// Sylvain Gougouzian

Développeur Auvergnat Rhônalpin

Formateur Numérique Responsable

gta
gta

express
express

📅 16 novembre 2010

⭐️ 66.2k

👥 326

🟨 JavaScript

Qu’est-ce que Bun ?

bun
bun
  • Concurrent de Node.js, Deno
  • Optimisé pour les performances (Développé en Zig)
  • Runtime, Bundler, Tests, ...
  • https://bun.sh

elysia
elysia

📅 24 décembre 2022

⭐️ 11.3k

👥 60

🟦 TypeScript

Hello World!

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(3000, () => {
  console.log(`Example app listening on port ${port}`);
});
import { Elysia } from 'elysia';

const app = new Elysia()
                  .get('/', 'Hello World!')
                  .listen(3000);

console.log(
    `Example app listening on port ${app.server?.port}`
);

Comparatif

21x faster than Express
21x faster than Express

https://saltyaom.com/blog/elysia-sucrose/

Sucrose

Static Code Analysis and Dynamic Code Injection using JIT compilation.

Sucrose

Eval

eval('console.log("Hello, World!")')

const say = new Function('something', 'console.log(something)')
say('Hello, World!')

Sucrose

const inference = sucrose({
	handler,
	...lifeCycle,
})

let fn = 'const context = {'

if(inference.body)
	fn += 'body: await parseBody(body)\n'

fn += '}'
fn += `return handler(context)`

return new Function('context', fn)

Plugins

Streams

import { Elysia } from 'elysia';

const app = new Elysia()
    .get('/ok', function* ({ set }) {
      set.headers['x-name'] = 'Elysia'
      yield "1"
      yield "2"
    });

Let’s go to code

bun create elysia app

Objectif

Chat avec Inscription et API Rest en moins de 10 minutes

Merci