API foundations

Create a Hono Node project

Scaffold a TypeScript API on Node.js with Hono and run the local development server.

8 minute lesson

~~~

Hono builds on the web-standard Request and Response APIs and can run on Node.js or edge runtimes with the appropriate adapter.

Use the official project generator and select the Node.js template. The generated dependency versions become the project’s source of truth, so read its package.json rather than copying a version from the lesson.

npm create hono@latest books-api
# Select the nodejs template
cd books-api
npm install
npm run dev

Keep the Hono application separate from the Node.js adapter. The app owns routes and returns standard Response objects; the adapter owns the TCP server, port, and shutdown lifecycle. That boundary lets tests call app.request() without opening a socket and makes most application code portable to another Web API runtime.

Inspect the generated scripts, lockfile, Node requirement, and entry point before changing them. Start from a clean install, request the local URL with curl -i, and note the listening port. If the command starts but the request fails, distinguish a compile error, a server bound to a different port, and a handler returning an error instead of reinstalling dependencies blindly.

Start the server and find the exported Hono app, Node adapter entry point, and TypeScript configuration.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →