Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Creating a project

A Hono project is created with the official npm create hono command. It asks which platform the project is for and lays out ready-made files: the entry point, the TypeScript settings and the start scripts.

What you need

You need Node.js 22 or newer. Check the version in a terminal:

node -v

Creating the project

npm create hono@latest blog-api

The command asks a few questions:

  1. Which template do you want to use? — choose nodejs.
  2. Do you want to install project dependencies? — answer yes.
  3. Which package manager do you want to use? — choose npm.

Then go to the project folder and start the development server:

cd blog-api
npm run dev

The terminal shows Server is running on http://localhost:3000. Open that address and the browser shows the text "Hello Hono!".

Project structure

blog-api/
├── src/
│   └── index.ts        entry point: the app and the server start
├── node_modules/       installed packages
├── package.json        dependencies and scripts
├── tsconfig.json       TypeScript settings
└── .gitignore

The project is deliberately small: Hono does not impose a folder structure. You will split routes, middleware and database code into files yourself as the app grows.

Scripts

package.json already has three scripts:

CommandWhat it does
npm run devruns src/index.ts through tsx and restarts the server when a file is saved
npm run buildcompiles TypeScript to JavaScript into the dist/ folder
npm startruns the built dist/index.js with plain Node.js

tsx is a small program that runs TypeScript files without a separate compile step. It is only needed during development.

Dependencies

{
  "dependencies": {
    "@hono/node-server": "^1.14.0",
    "hono": "^4.7.0"
  }
}

hono is the framework itself, and @hono/node-server is the adapter that runs the app on Node.js. Your version numbers may differ; that is fine.

TypeScript settings

tsconfig.json turns on strict mode (strict) and contains JSX settings, which you will need in the lesson on HTML pages. Modules are set to NodeNext, so when you import your own files you write the .js extension, even though the file is named .ts:

// src/index.ts
import { posts } from './routes/posts.js'

Common mistake

Pick the template for the platform where the server will run. If you choose cloudflare-workers or bun, the files and start commands are different, and the course examples with @hono/node-server will not run. For this course choose nodejs. If you picked the wrong one, it is easier to create the project again.

Thanks for reading!

Donate to the site — we work hard for you.