logoalt Hacker News

Show HN: Nub – A Bun-like all-in-one toolkit for Node.js

262 pointsby colinmcdyesterday at 2:14 PM73 commentsview on HN

Colin here, creator of Nub. I’ve had the general shape of this in mind for years. Nub runs your code with stock `node`, augmented with a `--require` preload hook[0] that adds a transpiler (oxc-powered, packaged as a Node-API add-on), registers a module resolution hook[1], and injects polyfills as needed for APIs like `Worker`, `Temporal`, etc. All purely additive, your code ultimately runs using Node’s actual engine & stdlib implementations.

[0] https://nodejs.org/api/cli.html#-require-module

[1] https://nodejs.org/api/module.html#moduleregisterhooksoption...


Comments

pier25yesterday at 10:12 PM

Very cool idea which makes a lot of sense. Bun provides more (eg db drivers) but the DX is certainly a big part of its appeal.

For reference, the main author of Nub is Colin McDonnell who created Zod and even worked at Bun at some point.

show 1 reply
eyelidlessnessyesterday at 4:44 PM

I’m surprised to see this using a `--require` hook (rather than `--import`). Maybe something’s changed significantly since I was looking into building some similar functionality… but it makes me wonder about nuances in nub’s ESM support.

(When I was investigating this it was very early in Node’s `--import` story, but there were several edge cases with the more common ESM-to-CJS approaches that I wanted to address. Most were probably exceedingly niche concerns, but I’d expect top-level await to affect a meaningful subset of users.)

show 1 reply
vmspyesterday at 11:28 PM

Hasn't Node been able to run TypeScript for a couple of versions? Why's the transpiler needed?

show 2 replies
ssalbdivadyesterday at 2:57 PM

Just merged a PR migrating our entire monorepo to nub.

0 issues, ridiculously fast.

show 1 reply
austin-cheneytoday at 9:44 AM

The readme says Websockets support is native from Node 22, except Node does not have a native Websockets library. Their link for Websockets standard goes to MDN, which is fine except that only describes the WHATWG user interface and nothing about the protocol or how Websockets works.

It feels like this is missing something or using a nonnative library as a supplemental addition.

haburkayesterday at 8:16 PM

I actually really like this! Great choices all around.

awaseemyesterday at 3:59 PM

I saw this on twitter and loved it, such a good move on your part Colin. Hope the project picks up tons of steam!

ivanjermakovyesterday at 4:09 PM

Respect for embracing existing tech instead of rewriting a worse version of it. Wonder where we would be today if all alternative-building effort went to Node instead (with proper leadership).

show 2 replies
gorjusborgyesterday at 3:38 PM

Very smart. You can't lose all your customers for vibe-coding a migration to Rust if you are already written in Rust ;)

show 7 replies
zarzavattoday at 5:04 AM

This looks fantastic.

One suggestion, for package management you should just wrap pnpm, my desire to move to anything else is nil.

show 1 reply
sgarrityyesterday at 3:21 PM

I didn't even click on the link. I just came to give the author a hat-tip on the project name. Well played.

show 2 replies
jpambrunyesterday at 6:39 PM

Am I expected to be able to run this in production on the backend, or do I still need to transpile and bundle? Do we expect the performance and memory overhead to be negligible. What would be the expectations on terms of added attack surface?

show 1 reply
kandrosyesterday at 4:14 PM

Love the idea, learning a lot of interesting things about node hooks by reading docs and some code

skybrianyesterday at 4:45 PM

> TypeScript-friendly resolution: extensionless imports, tsconfig.json#paths

I’m wondering how that works. Deno has very complicated import resolution, so building my own import resolver to be compatible with it is a bit of a pain. (This is for a custom lint-like tool.)

cozzydyesterday at 11:49 PM

I know some people who pronounce n00b like nub, which makes this sort of funny to me. (Maybe it's even intentional?)

bookernathyesterday at 3:08 PM

Nice, I think this fills a niche. Does it work on cloudflare workers?

show 1 reply
vivzkestreltoday at 5:51 AM

- eli 5 : what is so great about this

montroseryesterday at 4:34 PM

Nice. Can we get `nub --compile` up in there like Bun has?

show 1 reply
Onavoyesterday at 8:21 PM

There's also the option of using Jiti

https://github.com/unjs/jiti

It would add an extra dependency though

esafakyesterday at 7:17 PM

Will you be able to integrate aube updates after vendoring it? https://github.com/nubjs/nub/pull/81

show 1 reply
nsonhatoday at 3:20 AM

what's wrong with bun? And how is this better?

eezingtoday at 3:10 PM

[dead]

GL26yesterday at 3:13 PM

nice ! does this work on docker containers ?

show 1 reply