Quick Start
Create a new Hono project for Node.js:Installation
Add Hono to your existing Node.js project:Basic Usage
Using Node.js Adapter
Create your application with the Node.js adapter:index.ts
Using Native Node.js APIs
For Node.js v18.0.0+, you can use native fetch support:index.ts
Using
@hono/node-server is recommended as it handles request/response conversion automatically.Running Your App
With TypeScript
Usingtsx for development:
package.json:
package.json
With JavaScript
Adapter Features
Static Files
Serve static files using the node-server adapter:Connection Info
Get connection information:Environment Variables
Load environment variables usingdotenv:
.env
index.ts
Database Integration
PostgreSQL with Drizzle ORM
MongoDB
Middleware
CORS
Logger
Testing
Use any Node.js testing framework. Example with Vitest:index.test.ts
Deployment
VPS/Cloud Server
1
Build your application
2
Install dependencies on server
3
Run with PM2
Install PM2:Start your app:
Docker
Create aDockerfile:
Dockerfile
Heroku
Create aProcfile:
Best Practices
Use process managers in production
Use process managers in production
Use PM2 or systemd to keep your app running and handle restarts.
Enable clustering for multi-core
Enable clustering for multi-core
Use Node.js cluster module or PM2 cluster mode for better performance.
Handle errors gracefully
Handle errors gracefully
Implement proper error handling and logging.
Use TypeScript
Use TypeScript
TypeScript provides better type safety and developer experience.
Performance Tips
- Use Node.js v20+ for best performance
- Enable HTTP/2 with the
http2module - Implement caching strategies (Redis, in-memory)
- Use a reverse proxy (nginx, Caddy) in production
- Enable gzip/brotli compression
Resources
Node.js Documentation
Official Node.js documentation
@hono/node-server
Node.js adapter for Hono