Skip to content

Examples ​

The repository includes runnable examples for the main deployment targets.

Minimal JSX app ​

examples/minimal.tsx shows the shortest path to a JSX app running on Bun.

tsx
import { app } from 'jinatra'
import { serve } from 'jinatra/bun'

get('/', () => <h1>Jinatra</h1>)
get('/hello/:name', () => <h1>Hello {params.name}</h1>)

serve(app, { port: 3000 })

Node server ​

examples/node-server.js uses the Node adapter and native static file serving.

EJS views ​

examples/ejs-server.js is a runnable Node server using native EJS templates from examples/views/. Put templates in views/ and return view() from a route. The template and optional layout names may omit the .ejs suffix:

js
import { view } from 'jinatra';
import { serve } from 'jinatra/node';
import app from './app.js';

app.get('/', () => view('home', { title: 'Jinatra' }, 'layout'));
serve(app);

views/home.ejs:

html
<h1><%= title %></h1>

views/layout.ejs:

html
<!doctype html>
<html><body><%- body %></body></html>

Use serve(app, { views: './templates' }) or new Jinatra({ views: './templates' }) for another template directory.

Cloudflare Worker ​

examples/cloudflare-worker.js demonstrates a Worker export, cron handling, and Workers Static Assets.

Run the tests ​

bash
npm test

The test suite exercises routing, request context, middleware, responses, sessions, Cloudflare behavior, JSX SSR, and the Node adapter.

Released under the MIT License.