Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@honojs/node-server

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@honojs/node-server

HTTP Server for Hono on Node.js

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
3
Weekly downloads
 
Created
Source

Hono on Node.js

This project is still experimental.

This is HTTP Server for Hono on Node.js. Hono is ultrafast web framework for Cloudflare Workers, Deno, and Bun. It's not for Node.js. BUT, there may be a case that you really want to run on Node.js. This library is an adapter server that connects Hono and Node.js.

Hono is ultra fast, but not so fast on Node.js, because there is an overhead to adapt Hono's API to Node.js.

By the way, it is 2.x times faster than Express.

Install

You can install from npm registry with npm command:

npm install @honojs/node-server

Or use yarn:

yarn add @honojs/node-server

Usage

Just import @honojs/node-server at the top and write the code as usual. The same code that runs on Cloudflare Workers, Deno, and Bun will work.

import { serve } from '@honojs/node-server' // Write above `Hono`
import { Hono } from 'hono'

const app = new Hono()
app.get('/', (c) => c.text('Hono meets Node.js'))

serve(app)

For example, run it using ts-node. Then an HTTP server will be launched. The default port is 3000.

ts-node ./index.ts

Open http://localhost:3000 with your browser.

Options

serve({
  fetch: app.fetch,
  port: 8787, // Port number, default is 3000
})

Middleware

Most built-in middleware also works with Node.js. Read the documentation and use the Middleware of your liking.

import { serve } from '@honojs/node-server'
import { Hono } from 'hono'
import { prettyJSON } from 'hono/pretty-json'

const app = new Hono()

app.get('*', prettyJSON())
app.get('/', (c) => c.json({ 'Hono meets': 'Node.js' }))

serve(app)

Serve Static Middleware

Use Serve Static Middleware that has been created for Node.js.

import { serve, serveStatic } from '@honojs/node-server'

//...

app.use('/static/*', serveStatic({ root: './' }))

Author

Yusuke Wada https://github.com/yusukebe

License

MIT

FAQs

Package last updated on 01 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc