Unlisted
Like
ZenServer
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v230View latest version
Source: https://hono.dev/docs/getting-started/deno
Follow the official Deno installation guide.
Start a new project with:
deno init --npm hono my-app cd my-app
Select the deno template if prompted.
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Deno!'))
Deno.serve(app.fetch)
deno task start
Specify a port in main.ts:
Use serveStatic from hono/deno:
import { Hono } from 'hono'
import { serveStatic } from 'hono/deno'
const app = new Hono()
app.use('/static/*', serveStatic({ root: './' }))
app.use('/favicon.ico', serveStatic({ path: './favicon.ico' }))
app.get('/', (c) => c.text('You can access: /static/hello.txt'))
app.get('*', serveStatic({ path: './static/fallback.txt' }))
Deno.serve(app.fetch)
You can customize static file serving with options like rewriteRequestPath, mimes, onFound, onNotFound, and precompressed.
Write tests using Deno's built-in test runner:
import { Hono } from 'hono'
import { assertEquals } from '@std/assert'
Deno.test('Hello World', async () => {
const app = new Hono()
app.get('/', (c) => c.text('Please test me'))
const res = await app.request('http://localhost/')
assertEquals(res.status, 200)
})
Run with:
deno test hello.ts
You can use either jsr:@hono/hono or npm:hono in your deno.json imports:
{ "imports": { "hono": "jsr:@hono/hono" } }
Or for npm:
{ "imports": { "hono": "npm:hono", "zod": "npm:zod", "@hono/zod-validator": "npm:@hono/zod-validator" } }
For more details and advanced options, see the full documentation at https://hono.dev/docs/getting-started/deno.