### Elysia Server with Logging Source: https://elysiajs.com/tutorial This example shows a basic Elysia server setup that logs its running address to the console. It includes initializing Elysia, defining a root GET route, and starting the server. ```typescript import { Elysia } from 'elysia' const app = new Elysia() .get('/', 'Hello World!') .listen(3000) console.log( `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}` ) ``` -------------------------------- ### Basic WebSocket Setup Source: https://elysiajs.com/patterns/websocket.html This example demonstrates the fundamental setup of a WebSocket server using ElysiaJS. It establishes a '/ws' endpoint where incoming messages are echoed back to the client. ```APIDOC ## POST /ws ### Description Establishes a WebSocket connection and echoes incoming messages back to the client. ### Method POST ### Endpoint /ws ### Request Body (No specific request body defined for initial connection, message content is handled in `message` callback) ### Response (Echoes the received message back to the client) ### Request Example ```typescript import { Elysia } from 'elysia' new Elysia() .ws('/ws', { message(ws, message) { ws.send(message) } }) .listen(3000) ``` ### Response Example (Echoes the received message) ``` -------------------------------- ### Main ElysiaJS Server Setup Source: https://elysiajs.com/blog/elysia-supabase This code initializes the ElysiaJS application and integrates the authentication module. It then starts the server and logs its address. ```typescript import { Elysia, t } from 'elysia' import { auth } from './modules' const app = new Elysia() .use(auth) .listen(3000) console.log( `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}` ) ``` -------------------------------- ### Basic Elysia Node.js Setup Source: https://elysiajs.com/integrations/node Initialize Elysia with the Node adapter and define a simple GET route. This is the minimal setup required to run Elysia on Node.js. ```typescript import { Elysia } from 'elysia' import { node } from '@elysia/node' const app = new Elysia({ adapter: node() }) .get('/', () => 'Hello Elysia') .listen(3000) ``` -------------------------------- ### ElysiaJS Hello World Example Source: https://elysiajs.com/tutorial A basic ElysiaJS application demonstrating GET, POST, and dynamic route parameters. Starts a server on port 3000. ```typescript import { Elysia } from 'elysia' new Elysia() .get('/', 'Hello Elysia') .get('/user/:id', ({ params: { id }}) => id) .post('/form', ({ body }) => body) .listen(3000) ``` -------------------------------- ### Basic ElysiaJS Server Setup Source: https://elysiajs.com/ A simple ElysiaJS server demonstrating basic GET requests, file serving, streaming, and WebSocket handling. Requires ElysiaJS and Bun. ```typescript import { Elysia, file } from 'elysia' new Elysia() .get('/', 'Hello World') .get('/image', file('mika.webp')) .get('/stream', function* () { yield 'Hello' yield 'World' }) .ws('/realtime', { message(ws, message) { ws.send('got:' + message) } }) .listen(3000) ``` -------------------------------- ### Install Server Timing Plugin Source: https://elysiajs.com/plugins/server-timing Install the Server Timing plugin using bun. ```bash bun add @elysia/server-timing ``` -------------------------------- ### Install Prisma and Prismabox Source: https://elysiajs.com/integrations/prisma.html Install the necessary Prisma client, Prismabox, and adapter packages using Bun. The Prisma CLI is installed as a dev dependency. ```bash bun add @prisma/client prismabox prisma-adapter-bun-sqlite && \ bun add -d prisma ``` -------------------------------- ### Install Elysia Static Plugin Source: https://elysiajs.com/plugins/static Install the @elysia/static plugin using bun. ```bash bun add @elysiajs/static ``` -------------------------------- ### Basic Elysia Server Setup Source: https://elysiajs.com/tutorial/getting-started/handler-and-context A minimal Elysia application setup that defines a single GET route and listens on port 3000. ```typescript import { Elysia } from 'elysia' new Elysia() .get('/', 'Hello Elysia!') .listen(3000) ``` -------------------------------- ### Define a Basic GET Route Source: https://elysiajs.com/tutorial/getting-started/your-first-route Defines a simple GET route for the root path '/' that responds with 'Hello World!' and starts a server on port 3000. ```typescript import { Elysia } from 'elysia' new Elysia() .get('/', 'Hello World!') .listen(3000) ``` -------------------------------- ### Install JWT Plugin Source: https://elysiajs.com/plugins/jwt.html Install the JWT plugin using Bun. ```bash bun add @elysiajs/jwt ``` -------------------------------- ### Install Elysia Node Adapter (Bun) Source: https://elysiajs.com/integrations/node Install the Elysia core library and the Node adapter using Bun package manager. ```bash bun add elysia @elysia/node ``` -------------------------------- ### Install GraphQL Yoga Plugin Source: https://elysiajs.com/plugins/graphql-yoga Install the GraphQL Yoga plugin for Elysia using Bun. ```bash bun add @elysia/graphql-yoga ``` -------------------------------- ### Basic OpenTelemetry Setup in Elysia Source: https://elysiajs.com/plugins/opentelemetry.html This snippet demonstrates how to install and apply the OpenTelemetry plugin to an Elysia instance. It configures a BatchSpanProcessor with an OTLPTraceExporter. ```typescript import { Elysia } from 'elysia' import { opentelemetry } from '@elysia/opentelemetry' import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-node' import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' new Elysia() .use( opentelemetry({ spanProcessors: [ new BatchSpanProcessor( new OTLPTraceExporter() ) ] }) ) ``` -------------------------------- ### Basic OpenTelemetry Setup Source: https://elysiajs.com/patterns/opentelemetry.html Install the OpenTelemetry plugin and apply it to your Elysia instance with a single line of configuration. ```typescript import { Elysia } from 'elysia' import { opentelemetry } from '@elysia/opentelemetry' new Elysia() .use(opentelemetry()) ``` -------------------------------- ### Basic Elysia Static Plugin Setup Source: https://elysiajs.com/patterns/fullstack-dev-server.html Installs and uses the Elysia Static plugin to enable the Fullstack Dev Server. Requires 'await' before staticPlugin() to set up HMR hooks. ```typescript import { Elysia } from 'elysia' import { staticPlugin } from '@elysia/static' new Elysia() .use(await staticPlugin()) .listen(3000) ``` -------------------------------- ### Install Elysia HTML Plugin Source: https://elysiajs.com/plugins/html.html Install the Elysia HTML plugin using Bun. ```bash bun add @elysia/html ``` -------------------------------- ### Install OpenAPI Plugin Source: https://elysiajs.com/patterns/openapi.html Install the OpenAPI plugin for ElysiaJS using Bun. ```bash bun add @elysiajs/openapi ``` -------------------------------- ### Install Dependencies Source: https://elysiajs.com/blog/elysia-supabase Install the release candidate versions of Elysia, cookie plugin, and the Supabase JavaScript client. ```bash bun add elysia@rc @elysiajs/cookie@rc @supabase/supabase-js ``` -------------------------------- ### Install Bearer Plugin Source: https://elysiajs.com/plugins/bearer Install the @elysiajs/bearer plugin using bun. ```bash bun add @elysiajs/bearer ``` -------------------------------- ### Install Bun on Windows Source: https://elysiajs.com/quick-start Use this command to install Bun on Windows systems via PowerShell. ```powershell powershell -c "irm bun.sh/install.ps1 | iex" ``` -------------------------------- ### Install Bun on MacOS/Linux Source: https://elysiajs.com/quick-start Use this command to install Bun on macOS or Linux systems. ```bash curl -fsSL https://bun.sh/install | bash ``` -------------------------------- ### Install Elysia Node Adapter (npm) Source: https://elysiajs.com/integrations/node Install the Elysia core library and the Node adapter using npm package manager. ```bash npm install elysia @elysia/node ``` -------------------------------- ### Configure Environment Variables Source: https://elysiajs.com/blog/elysia-supabase Example structure for the .env file containing Supabase credentials. ```bash # .env supabase_url=https://********************.supabase.co supabase_service_role=**** **** **** **** ``` -------------------------------- ### Basic Better Auth Setup Source: https://elysiajs.com/integrations/better-auth.html Initialize Better Auth with a database connection. This is the foundational step for using Better Auth. ```typescript import { betterAuth } from 'better-auth' import { Pool } from 'pg' export const auth = betterAuth({ database: new Pool() }) ``` -------------------------------- ### Install Elysia Node Adapter (yarn) Source: https://elysiajs.com/integrations/node Install the Elysia core library and the Node adapter using yarn package manager. ```bash yarn add elysia @elysia/node ``` -------------------------------- ### Install Development Dependencies (Bun) Source: https://elysiajs.com/integrations/node Install tsx, @types/node, and typescript as development dependencies using Bun. ```bash bun add -d tsx @types/node typescript ``` -------------------------------- ### Basic GraphQL Yoga Setup Source: https://elysiajs.com/plugins/graphql-yoga Set up a basic GraphQL Yoga server with Elysia, defining type definitions and resolvers. ```typescript import { Elysia } from 'elysia' import { yoga } from '@elysia/graphql-yoga' const app = new Elysia() .use( yoga({ typeDefs: /* GraphQL */ ` type Query { hi: String } `, resolvers: { Query: { hi: () => 'Hello from Elysia' } } }) ) .listen(3000) ``` -------------------------------- ### Unit Test with Vitest Source: https://elysiajs.com/tutorial/features/unit-test An example of unit testing an Elysia application using the Vitest testing framework. It asserts that a GET request to the root path returns 'Hello World'. ```typescript import { describe, it, expect } from 'vitest' import { Elysia } from 'elysia' describe('Elysia', () => { it('should return Hello World', async () => { const app = new Elysia().get('/', 'Hello World') const text = await app.fetch(new Request('http://localhost/')) .then(res => res.text()) expect(text).toBe('Hello World') }) }) ``` -------------------------------- ### Mount Hono App in Elysia with Port Listening Source: https://elysiajs.com/tutorial/features/mount A concise example of mounting a Hono application's fetch handler into Elysia and starting the Elysia server on port 3000. This is suitable for testing integrated applications. ```typescript import { Elysia, t } from 'elysia' import { Hono } from 'hono' const hono = new Hono() .get('/', (c) => c.text('Hello from Hono')) new Elysia() .get('/', 'Hello from Elysia') .mount('/hono', hono.fetch) .listen(3000) ``` -------------------------------- ### Install Elysia Node Adapter (pnpm) Source: https://elysiajs.com/integrations/node Install the Elysia core library and the Node adapter using pnpm package manager. ```bash pnpm add elysia @elysia/node ``` -------------------------------- ### Install Elysia Eden Source: https://elysiajs.com/eden/installation.html Install the Elysia Eden package for your frontend project using Bun. ```bash bun add @elysia/eden bun add -d elysia ``` -------------------------------- ### Initialize WebSocket Server Source: https://elysiajs.com/patterns/websocket.html Basic setup for a WebSocket route using Elysia.ws(). ```typescript import { Elysia } from 'elysia' new Elysia() .ws('/ws', { message(ws, message) { ws.send(message) } }) .listen(3000) ``` ```typescript import { Elysia } from 'elysia' const app = new Elysia() .ws('/ws', { message(ws, message) { ws.send(message) } }) .listen(3000) ``` -------------------------------- ### Install Netlify CLI with Bun Source: https://elysiajs.com/integrations/netlify Install the Netlify CLI globally using Bun to simulate Netlify Edge Functions locally. This command is used for local development and testing. ```bash bun add -g netlify-cli ``` -------------------------------- ### Install CORS Plugin Source: https://elysiajs.com/plugins/cors Install the ElysiaJS CORS plugin using Bun. ```bash bun add @elysiajs/cors ``` -------------------------------- ### Install GraphQL Apollo Plugin Source: https://elysiajs.com/plugins/graphql-apollo Install the necessary packages for the Elysia GraphQL Apollo plugin using bun. ```bash bun add graphql @elysia/apollo @apollo/server ``` -------------------------------- ### Installing Production Dependencies Source: https://elysiajs.com/patterns/deploy.html Installs only the production dependencies listed in `package.json`. This command should be run on the production server after deployment. ```bash bun install --production ``` -------------------------------- ### Initialize Elysia with Deno.serve Source: https://elysiajs.com/integrations/deno Wrap the Elysia fetch handler within Deno.serve to start the application. ```typescript import { Elysia } from 'elysia' const app = new Elysia() .get('/', () => 'Hello Elysia') .listen(3000) Deno.serve(app.fetch) ``` -------------------------------- ### Install Optional Peer Dependencies Source: https://elysiajs.com/plugins/graphql-yoga Install optional peer dependencies for GraphQL Yoga. ```bash bun add graphql graphql-yoga ``` -------------------------------- ### Install React Email and Dependencies Source: https://elysiajs.com/integrations/react-email.html Install React Email and its peer dependencies using Bun. Add the email development script to your package.json. ```bash bun add -d react-email bun add @react-email/components react react-dom ``` ```json { "scripts": { "email": "email dev --dir src/emails" } } ``` -------------------------------- ### Clone and Run Type Gen Example Source: https://elysiajs.com/tutorial/features/openapi Clone the Elysia Type Gen Example repository and run it locally to try out the type inference feature for OpenAPI schema generation. This requires Node.js (bun) environment. ```bash git clone https://github.com/SaltyAom/elysia-typegen-example && \ cd elysia-typegen-example && \ bun install && \ bun run dev ``` -------------------------------- ### Install Development Dependencies (npm) Source: https://elysiajs.com/integrations/node Install tsx, @types/node, and typescript as development dependencies using npm. ```bash npm install --save-dev tsx @types/node typescript ``` -------------------------------- ### Install Development Dependencies (yarn) Source: https://elysiajs.com/integrations/node Install tsx, @types/node, and typescript as development dependencies using yarn. ```bash yarn add -D tsx @types/node typescript ``` -------------------------------- ### Install Development Dependencies (pnpm) Source: https://elysiajs.com/integrations/node Install tsx, @types/node, and typescript as development dependencies using pnpm. ```bash pnpm add -D tsx @types/node typescript ``` -------------------------------- ### Basic HTTP Methods Source: https://elysiajs.com/essential/route.html Demonstrates the basic usage of GET, POST, and LISTEN methods in Elysia. ```typescript import { Elysia } from 'elysia' new Elysia() .get('/', 'hello') .post('/hi', 'hi') .listen(3000) ``` -------------------------------- ### Install Bun Type Definitions Source: https://elysiajs.com/eden/installation.html Install Bun type definitions if you are using Bun-specific features in your Elysia handlers and need them for client-side type inference. ```bash bun add -d @types/bun ``` -------------------------------- ### Install nuxt-elysia Plugin Source: https://elysiajs.com/integrations/nuxt Install the necessary packages for integrating Elysia with Nuxt. This includes Elysia, Eden Treaty, and the nuxt-elysia development dependency. ```bash bun add elysia @elysia/eden bun add -d nuxt-elysia ``` -------------------------------- ### Install Prisma CLI Source: https://elysiajs.com/blog/with-prisma Add Prisma CLI as a development dependency using 'bun add -d'. ```typescript bun add -d prisma ``` -------------------------------- ### Install ElysiaJS Cron Plugin Source: https://elysiajs.com/plugins/cron.html Install the cron plugin using Bun. This is the first step before using cron jobs in your Elysia application. ```bash bun add @elysia/cron ``` -------------------------------- ### Initialize Prisma Project Source: https://elysiajs.com/blog/with-prisma Execute 'prisma init' using 'bunx' to set up your Prisma project. This command is equivalent to 'npx prisma init'. ```typescript bunx prisma init ``` -------------------------------- ### Initialize Elysia Project Source: https://elysiajs.com/blog/elysia-supabase Command to scaffold a new ElysiaJS project using Bun. ```bash bun create elysia elysia-supabase ``` -------------------------------- ### Example of Route Prefixing Source: https://elysiajs.com/patterns/configuration.html Illustrates how defining a prefix in the Elysia constructor results in all defined routes being appended with that prefix. ```typescript import { Elysia, t } from 'elysia' new Elysia({ prefix: '/v1' }).get('/name', 'elysia') // Path is /v1/name ``` -------------------------------- ### Basic Routing with GET Method Source: https://elysiajs.com/essential/route.html Defines basic routes for the root path and '/hi' using the GET method. The server listens on port 3000. ```typescript import { Elysia } from 'elysia' new Elysia() .get('/', 'hello') .get('/hi', 'hi') .listen(3000) ``` -------------------------------- ### Elysia Limitation: Response Definition Before Server Start Source: https://elysiajs.com/integrations/cloudflare-worker.html This TypeScript example demonstrates an invalid pattern where a response is defined before the server starts, which will result in an error in Cloudflare Worker environments. ```typescript import { Elysia } from 'elysia' new Elysia() // This will throw error .get('/', 'Hello Elysia') .listen(3000) ``` -------------------------------- ### Trace Listener Example Source: https://elysiajs.com/patterns/trace.html This example shows how to use a trace listener for a specific lifecycle event, in this case 'onBeforeHandle'. The listener receives a parameter object with details about the event, including its name, start time, and end time. ```typescript import { Elysia } from 'elysia' const app = new Elysia() .trace(({ onBeforeHandle }) => { // This is trace listener // hover to view the type onBeforeHandle((parameter) => { }) }) .get('/', () => 'Hi') .listen(3000) ``` -------------------------------- ### Define a Basic Handler Source: https://elysiajs.com/essential/handler.html A handler can be a function that accepts no arguments and returns a value. This example shows a simple GET route returning a string. ```typescript import { Elysia } from 'elysia' new Elysia() // the function `() => 'hello world'` is a handler .get('/', () => 'hello world') .listen(3000) ``` -------------------------------- ### Initialize Elysia Server with Auth and Post Modules Source: https://elysiajs.com/blog/elysia-supabase Sets up the main Elysia application, incorporating authentication and post-related modules, and starts the server. Logs the server's address to the console. ```typescript import { Elysia, t } from 'elysia' import { auth, post } from './modules' const app = new Elysia() .use(auth) .use(post) .listen(3000) console.log( `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}` ) ``` -------------------------------- ### Create Elysia API Route Source: https://elysiajs.com/integrations/nuxt Define a simple Elysia API route in `api.ts`. This example creates a GET endpoint '/hello' that returns a JSON message. ```typescript export default () => new Elysia() .get('/hello', () => ({ message: 'Hello world!' })) ``` -------------------------------- ### Create New ElysiaJS Project Source: https://elysiajs.com/quick-start Automatically sets up a new ElysiaJS project with all necessary configurations. Navigate into the created 'app' directory afterwards. ```bash bun create elysia app ``` ```bash cd app ``` -------------------------------- ### Monorepo Dockerfile with Multiple Package Copies Source: https://elysiajs.com/patterns/deploy.html A Dockerfile for a monorepo setup using Bun. It copies package.json files from both the app and shared packages before installation to ensure correct dependency caching. ```dockerfile FROM oven/bun:1 AS build WORKDIR /app # Cache packages COPY package.json package.json COPY bun.lock bun.lock COPY /apps/server/package.json ./apps/server/package.json COPY /packages/config/package.json ./packages/config/package.json RUN bun install COPY /apps/server ./apps/server COPY /packages/config ./packages/config ENV NODE_ENV=production RUN bun build \ --compile \ --minify-whitespace \ --minify-syntax \ --outfile server \ src/index.ts FROM gcr.io/distroless/base WORKDIR /app COPY --from=build /app/server server ENV NODE_ENV=production CMD ["./server"] EXPOSE 3000 ``` -------------------------------- ### Basic GraphQL Apollo Setup Source: https://elysiajs.com/plugins/graphql-apollo Set up a basic GraphQL server with Apollo using Elysia. Define type definitions and resolvers to handle queries. ```typescript import { Elysia } from 'elysia' import { apollo, gql } from '@elysia/apollo' const app = new Elysia() .use( apollo({ typeDefs: gql` type Book { title: String author: String } type Query { books: [Book] } `, resolvers: { Query: { books: () => { return [ { title: 'Elysia', author: 'saltyAom' } ] } } } }) ) .listen(3000) ``` -------------------------------- ### Unit Test with Jest Source: https://elysiajs.com/tutorial/features/unit-test An example of unit testing an Elysia application using the Jest testing framework. It checks if a GET request to the root path correctly returns 'Hello World'. ```typescript import { describe, it, test } from '@jest/globals' import { Elysia } from 'elysia' describe('Elysia', () => { test('should return Hello World', async () => { const app = new Elysia().get('/', 'Hello World') const text = await app.fetch(new Request('http://localhost/')) .then(res => res.text()) expect(text).toBe('Hello World') }) }) ``` -------------------------------- ### Creating and Using a Basic Plugin Source: https://elysiajs.com/essential/plugin.html Demonstrates how to define a simple plugin with a decoration and a route, and then use it within a main Elysia instance. ```typescript import { Elysia } from 'elysia' const plugin = new Elysia() .decorate('plugin', 'hi') .get('/plugin', ({ plugin }) => plugin) const app = new Elysia() .use(plugin) .get('/', ({ plugin }) => plugin) .listen(3000) ``` -------------------------------- ### Unit Test with Bun Test Source: https://elysiajs.com/tutorial/features/unit-test An example of unit testing an Elysia application using the 'bun:test' testing framework. It verifies that a GET request to the root path returns 'Hello World'. ```typescript import { describe, it, expect } from 'bun:test' import { Elysia } from 'elysia' describe('Elysia', () => { it('should return Hello World', async () => { const app = new Elysia().get('/', 'Hello World') const text = await app.fetch(new Request('http://localhost/')) .then(res => res.text()) expect(text).toBe('Hello World') }) }) ``` -------------------------------- ### Basic Elysia Server in SvelteKit Route Source: https://elysiajs.com/integrations/sveltekit Integrate a basic Elysia server into a SvelteKit route handler. This example defines GET and POST endpoints and exports a fallback function to handle requests. ```typescript // src/routes/[...slugs]/+server.ts import { Elysia, t } from 'elysia'; const app = new Elysia() .get('/', 'hello SvelteKit') .post('/', ({ body }) => body, { body: t.Object({ name: t.String() }) }) interface WithRequest { request: Request } export const fallback = ({ request }: WithRequest) => app.handle(request) ``` -------------------------------- ### Integrate OpenTelemetry with Elysia Source: https://elysiajs.com/blog/elysia-11 Install the `@elysiajs/opentelemetry` plugin to enable first-party support for OpenTelemetry. This setup collects span data from libraries compatible with the OpenTelemetry standard and automatically applies parent and child spans. ```typescript import { Elysia } from 'elysia' import { opentelemetry } from '@elysiajs/opentelemetry' import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-node' import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' new Elysia() .use( opentelemetry({ spanProcessors: [ new BatchSpanProcessor( new OTLPTraceExporter() ) ] }) ) ``` -------------------------------- ### Set up PostgreSQL Database with Docker Source: https://elysiajs.com/blog/with-prisma Run a PostgreSQL instance using Docker. This command maps port 5432 and sets a password for the 'postgres' user. ```bash docker run -p 5432:5432 -e POSTGRES_PASSWORD=12345678 -d postgres ``` -------------------------------- ### Eden Treaty Example: Interacting with Elysia Server Source: https://elysiajs.com/eden/overview.html Demonstrates how to use Eden Treaty to interact with an Elysia server, including making GET and PUT requests with type safety and auto-completion. Ensure the 'App' type is correctly imported from your server file. ```typescript import { treaty } from '@elysia/eden' import type { App } from './server' const app = treaty < App >('localhost:3000') app . // Call [GET] at '/' const { data } = await app . get () // Call [PUT] at '/nendoroid/:id' const { data : nendoroid , error } = await app . nendoroid ({ id : 1895 }). put ({ name : 'Skadi', from : 'Arknights' }) ``` -------------------------------- ### Install Drizzle Dependencies Source: https://elysiajs.com/integrations/drizzle.html Install the required Drizzle ORM and typebox integration packages. ```bash bun add drizzle-orm drizzle-typebox ``` -------------------------------- ### Create Elysia Project Source: https://elysiajs.com/blog/with-prisma Use 'bun create' to scaffold a new Elysia project. Replace 'elysia-prisma' with your desired project name. ```bash bun create elysia elysia-prisma ``` -------------------------------- ### Setup OpenTelemetry with PgInstrumentation Source: https://elysiajs.com/patterns/opentelemetry.html This snippet demonstrates how to initialize OpenTelemetry with the PgInstrumentation. Ensure the OpenTelemetry SDK is set up before importing the target module. ```typescript import { opentelemetry } from '@elysia/opentelemetry' import { PgInstrumentation } from '@opentelemetry/instrumentation-pg' export const instrumentation = opentelemetry({ instrumentations: [new PgInstrumentation()] }) ``` -------------------------------- ### Install Peer Dependencies for pnpm Source: https://elysiajs.com/integrations/astro Manually install required peer dependencies when using pnpm. ```bash pnpm add @sinclair/typebox openapi-types ``` -------------------------------- ### Run Elysia server with Deno Source: https://elysiajs.com/integrations/deno Use the Deno CLI to execute the server file. ```bash deno serve --watch src/index.ts ``` -------------------------------- ### ALL Method Source: https://elysiajs.com/essential/route.html Explains how to use Elysia.all to handle any HTTP method for a given path. ```APIDOC ## ALL method Elysia provides an `Elysia.all` for handling any HTTP method for a specified path using the same API like **Elysia.get** and **Elysia.post** ### Description Handles all HTTP methods (GET, POST, DELETE, etc.) for a specific path. ### Method ALL (any HTTP method) ### Endpoint / ### Parameters * **path**: Pathname * **function**: Function to respond to the client * **hook**: Additional metadata ### Request Example (No example provided in source) ### Response #### Success Response (200) (No specific response details provided in source) #### Response Example (No example provided in source) ``` -------------------------------- ### Initialize Elysia Project with Wrangler Source: https://elysiajs.com/integrations/cloudflare-worker.html Use Wrangler to initialize a new project for deploying Elysia on Cloudflare. ```bash wrangler init elysia-on-cloudflare ``` -------------------------------- ### Define Elysia Server in TanStack Start Route Source: https://elysiajs.com/integrations/tanstack-start.html Set up an Elysia server instance and export its fetch handler for use in TanStack Start server routes. This allows Elysia to manage API endpoints within the TanStack Start application. ```typescript import { Elysia } from 'elysia' import { createFileRoute } from '@tanstack/react-router' import { createIsomorphicFn } from '@tanstack/react-start' const app = new Elysia({ prefix: '/api' }).get('/', 'Hello Elysia!') const handle = ({ request }: { request: Request }) => app.fetch(request) export const Route = createFileRoute('/api/$')({ server: { handlers: { GET: handle, POST: handle } } }) ``` -------------------------------- ### Install Peer Dependencies for pnpm Source: https://elysiajs.com/integrations/nextjs.html If using pnpm, manually install required peer dependencies like @sinclair/typebox and openapi-types. ```bash pnpm add @sinclair/typebox openapi-types ``` -------------------------------- ### Install Additional Dependencies for pnpm Source: https://elysiajs.com/integrations/node Manually install @sinclair/typebox and openapi-types when using pnpm, as it does not auto-install peer dependencies by default. ```bash pnpm add @sinclair/typebox openapi-types ``` -------------------------------- ### Install Tailwind CSS Dependencies Source: https://elysiajs.com/patterns/fullstack-dev-server.html Installs Tailwind CSS version 4 and the Bun plugin for Tailwind CSS. These are development dependencies. ```bash bun add tailwindcss@4 bun add -d bun-plugin-tailwind ``` -------------------------------- ### Build Elysia Fullstack Server for Production Source: https://elysiajs.com/patterns/fullstack-dev-server.html Compiles the Elysia fullstack server into a single, self-contained executable file using Bun's build command. ```bash bun build --compile --target bun --outfile server src/index.ts ``` -------------------------------- ### Handling All HTTP Methods with Elysia.all Source: https://elysiajs.com/essential/route.html Demonstrates how to use Elysia.all to handle any HTTP method for a specified path, using the same API as other HTTP methods. ```typescript import { Elysia } from 'elysia' new Elysia() .all('/', 'hi') .listen(3000) ``` -------------------------------- ### ElysiaJS WebSocket Server and Client Setup Source: https://elysiajs.com/eden/treaty/websocket Sets up a basic WebSocket server in ElysiaJS and demonstrates a client subscribing to messages. Requires @elysiajs/elysia and @elysiajs/eden packages. ```typescript import { Elysia, t } from "elysia"; import { treaty } from "@elysia/eden"; const app = new Elysia() .ws("/chat", { body: t.String(), response: t.String(), message(ws, message) { ws.send(message); }, }) .listen(3000); const api = treaty("localhost:3000"); const chat = api.chat.subscribe(); chat.subscribe((message) => { console.log("got", message); }); chat.on("open", () => { chat.send("hello from client"); }); ``` -------------------------------- ### Initialize Supabase Client Source: https://elysiajs.com/blog/elysia-supabase Create a reusable Supabase client instance using environment variables. ```typescript // src/libs/supabase.ts import { createClient } from '@supabase/supabase-js' const { supabase_url, supabase_service_role } = process.env export const supabase = createClient(supabase_url!, supabase_service_role!) ``` -------------------------------- ### Bun Configuration for Preloading Source: https://elysiajs.com/patterns/opentelemetry.html This TOML configuration tells Bun to preload the specified instrumentation setup file before running the main application script. This ensures the OpenTelemetry SDK is initialized early. ```toml preload = ["./src/instrumentation.ts"] ``` -------------------------------- ### Basic Cron Job Setup Source: https://elysiajs.com/plugins/cron.html Set up a basic cron job that logs a message every 10 seconds. This demonstrates the core usage of the cron plugin. ```typescript import { Elysia } from 'elysia' import { cron } from '@elysia/cron' new Elysia() .use( cron({ name: 'heartbeat', pattern: '*/10 * * * * *', run() { console.log('Heartbeat') } }) ) .listen(3000) ```