Git Product home page Git Product logo

node-server's Introduction

Hono on Node.js

@honojs/node-server is renamed to @hono/node-serer !!


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 @hono/node-server

Or use yarn:

yarn add @hono/node-server

Usage

Just import @hono/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 '@hono/node-server'
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 '@hono/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 { serveStatic } from '@hono/node-server/serve-static'

//...

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

Related projects

Author

Yusuke Wada https://github.com/yusukebe

License

MIT

node-server's People

Contributors

yusukebe avatar tavvy avatar hoodgail avatar that-ambuj avatar onurgvnc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.