Getting started
Install
npm install jinatraOr with Bun:
bun add jinatraJinatra requires Node 18 or a runtime with the Fetch API. Bun is the shortest path from a file to a running server.
Create an app
Create server.js:
import { app } from 'jinatra'
import { serve } from 'jinatra/bun'
get('/', () => 'Hello from Jinatra')
get('/health', () => ({ ok: true }))
serve(app, { port: 3000 })Run it with:
bun run server.jsOpen http://localhost:3000 in your browser.
The default app and global helpers
app is Jinatra's default singleton app. Importing jinatra installs that app's route verbs (get, post, put, and so on) and request helpers on globalThis, so they can be used without importing each one. Pass the same app to your runtime adapter. For isolated apps, create new Jinatra() and use its methods directly instead.
Use an explicit app
The default app is convenient for a single application. For tests, libraries, or multiple apps, create an instance explicitly. An explicit instance keeps its routes separate, so use its methods directly:
import { Jinatra } from 'jinatra'
import { serve } from 'jinatra/bun'
const app = new Jinatra()
app.get('/', () => 'Hello from an explicit app')
serve(app)TypeScript and JSX
Configure the automatic JSX runtime in tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"jsxImportSource": "jinatra"
}
}Then return JSX directly from a route:
const Page = () => <main><h1>Jinatra</h1></main>
app.get('/', () => <Page />)JSX is rendered on the server. It is not hydrated in the browser.