Junction guide / Introduction
Getting started
Add the package, write one service and start the app. Junction runs on Bun only; Litestone is an optional peer that gives a service its CRUD from the schema.
bun add /junction
const app = createApp({
config: { ...defaultConfig, name: 'hello', hostname: '127.0.0.1', port: 0, apiPrefix: '/api' },
})
app.services.register(createService({
name: 'notes',
async find() { return [{ id: 1, title: 'Hello' }] },
}))
await app.start()
const res = await fetch(`http://127.0.0.1:${app.http.port}/api/notes`)
const body = await res.json() as { data: { title: string }[] }
if (res.status !== 200 || body.data[0].title !== 'Hello') throw new Error('unexpected answer')
await app.stop()
What else it can do
fli new my-appscaffolds the whole layout; Junction has no scaffolder of its ownportis3000unlessFRONTIER_PORT_BE,PORTor the config says otherwise, and0takes a free oneapiPrefixmoves every route the app registerscreateApp({ db })takes a Litestone client, and a service named for a model then needs no methods writtencreateApp({ root: import.meta.url })loadsservices/androutes/beside the fileapp.configure(health())addsGET /healthandGET /metrics- In a clone of the monorepo,
bun run devstarts the example app with--watchandbun run replopens a shell on it
In depth: README § Install, § Quick start