Skip to content

Conversation

@usualoma
Copy link
Member

@usualoma usualoma commented Oct 4, 2025

Starting with Node.js v24, experimental-strip-types is enabled by default. This allows us to run an app built with Hono in .ts format using very simple code and without external dependencies, simply by adding this PR.

While there are limitations, I find it convenient that you can run it in Node.js simply by changing the command, using exactly the same code as Deno or Bun.

$ cat app.ts
import { Hono } from 'hono'

const app = new Hono()
app.get('/', async (c) => {
  return c.json({ message: 'Hello World' })
})

export default app

$ npx @hono/node-server app.ts
Listening on http://localhost:3000

@usualoma
Copy link
Member Author

usualoma commented Oct 4, 2025

Hi @yusukebe

It's not exactly “super convenient,” but the ability to run on multiple runtimes with completely identical code feels Hono-like. What do you think?

@yusukebe
Copy link
Member

yusukebe commented Oct 5, 2025

@usualoma

Ah, interesting! Why have I never come up with this! I'll check the details later.

@yusukebe
Copy link
Member

yusukebe commented Oct 6, 2025

Hey @usualoma !

I think we don't have to hurry to decide whether to accept this PR or not. We have to consider well. I'll share my thoughts about this feature:

How about making this not depend on Hono

This script can be used for the app that uses the fetch interface, not Hono. Like this app:

export default {
  fetch: () => new Response('Hi')
}

So, it may be good to design support for all fetch interface apps.

I want to run JSX with this!

If we use this script, the app is usually run on Node.js. Now, it's wonderful that Node.js can run TypeScript! However, if the app uses JSX, it can't do so. I love the JSX feature of Hono. So it's better to work with JSX. I think we can do it with a builder like esbuild, though I don't know too much about the software for building. I have to investigate it.

But, to keep it simple, it will be better only to rely on Node.js type stripping.

Is it best to create the script in this @hono/node-server?

There are several options for distributing this script, not just including it in this @hono/node-server package. If we make it so it does not depend on Hono, it will be more effective. For example, we can create node-server-for-fetch-app (this is done intentionally for clarity). If so, it can cover more general use-cases. And we can name the script. For example, how about s as super super short?

$ s src/index.ts

(I like the naming serve, but there is already theserve package: https://www.npmjs.com/package/serve)

WinterTC started to consider the HTTP server API

This not only matters in Node.js matters, but, interestingly, WinterTC started to discuss the HTTP server API: WinterTC55/admin#137

If this is accepted, Node.js can follow the spec, and the interface will be implemented; therefore, we won't need to use this script. But it's a better idea to use this until it is enabled.


Anyway, this is an exciting idea.

@yusukebe
Copy link
Member

yusukebe commented Oct 8, 2025

This is a similar idea: https://github.com/h3js/srvx

@usualoma
Copy link
Member Author

usualoma commented Oct 8, 2025

Hi @yusukebe, thanks for the comment.

Indeed, it would be great if JSX worked too.

It seems https://github.com/h3js/srvx uses https://github.com/unjs/jiti.

https://github.com/h3js/srvx/blob/main/src/cli.ts#L265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants