Live data from Hacker News

Modern Node.js Patterns

kashw1n.com

261–270 of 448 posts

Re: Modern Node.js Patterns

#261

Earlier quoted context omitted.

> I wouldn't trust it to be done right. I don't understand this sort of complaint. Would you prefer that they didn't worked on this support ever? Exactly what's your point? Airing trust issues?

Node allows native addons in packages via the N-API so any native module aren't restricted by those permissions. Deno deals with this via --allow-ffi but these experimental Node permissions have nothing to disable the N-API, they just restrict the Node standard library.

> Node allows native addons in packages via the N-API so any native module aren't restricted by those permissions. (...) Node permissions (...) just restrict the Node standard library.

So what? That's clearly laid out in Node's documentation.

https://nodejs.org/api/permissions.html#file-system-permissi...

What point do you think you're making?

Re: Modern Node.js Patterns

#262

Earlier quoted context omitted.

I never needed those. I would just have an application wide object property like: text: { angry : "\u001b[1m\u001b[31m", blue : "\u001b[34m", bold : "\u001b[1m", boldLine : "\u001b[1m\u001b[4m", clear : "\u001b[24m\u001b[22m", cyan : "\u001b[36m", green : "\u001b[32m", noColor : "\u001b[39m", none : "\u001b[0m", purple : "\u001b[35m", red : "\u001b[31m", underline: "\u001b[4m", yellow : "\u001b[33m" } And then you ca…

I have a "ascii.txt" file ready to copy/paste the "book emoji" block chars to prepend my logs. It makes logs less noisy. HN can't display them, so I'll have to link to page w/ them: https://www.piliapp.com/emojis/books/

Why would you call that "ascii.txt"?

Re: Modern Node.js Patterns

#263
post #224

Earlier quoted context omitted.

I never needed those. I would just have an application wide object property like: text: { angry : "\u001b[1m\u001b[31m", blue : "\u001b[34m", bold : "\u001b[1m", boldLine : "\u001b[1m\u001b[4m", clear : "\u001b[24m\u001b[22m", cyan : "\u001b[36m", green : "\u001b[32m", noColor : "\u001b[39m", none : "\u001b[0m", purple : "\u001b[35m", red : "\u001b[31m", underline: "\u001b[4m", yellow : "\u001b[33m" } And then you ca…

This is the problem with people trying to be clever. Now you output escape sequences regardless of terminal setting. Using a library which handles that (an a thousand other quirks) makes much more sense

It depends on the audience / environment where your app is used. Public, a library is better. Internal / defined company environment, you don't need extra dependencies (but only when it comes to such simple solutions, that could be replaced easy with a lib).

Re: Modern Node.js Patterns

#264

Earlier quoted context omitted.

I never needed those. I would just have an application wide object property like: text: { angry : "\u001b[1m\u001b[31m", blue : "\u001b[34m", bold : "\u001b[1m", boldLine : "\u001b[1m\u001b[4m", clear : "\u001b[24m\u001b[22m", cyan : "\u001b[36m", green : "\u001b[32m", noColor : "\u001b[39m", none : "\u001b[0m", purple : "\u001b[35m", red : "\u001b[31m", underline: "\u001b[4m", yellow : "\u001b[33m" } And then you ca…

I have a "ascii.txt" file ready to copy/paste the "book emoji" block chars to prepend my logs. It makes logs less noisy. HN can't display them, so I'll have to link to page w/ them: https://www.piliapp.com/emojis/books/

Nice browser add-on https://johannhof.github.io/emoji-helper/

Re: Modern Node.js Patterns

#265

Earlier quoted context omitted.

It strips TS, it does not transpile. Things like TS enums will not work.

In Node 22.7 and above you can enable features like enums and parameter properties with the --experimental-transform-types CLI option (not to be confused with the old --experimental-strip-types option).

Excellent update! Thanks!

Re: Modern Node.js Patterns

#266
post #30

Earlier quoted context omitted.

I do miss the axios extensions tho, it was very easy to add rate-limits, throttling, retry strategies, cache, logging .. You can obviously do that with fetch but it is more fragmented and more boilerplate

Sounds like there's space for an axios-like library built on top of fetch.

Like axios can do it if you specify the fetch backend, it just won't do the .json() asynchronously.

Re: Modern Node.js Patterns

#267

Earlier quoted context omitted.

Node allows native addons in packages via the N-API so any native module aren't restricted by those permissions. Deno deals with this via --allow-ffi but these experimental Node permissions have nothing to disable the N-API, they just restrict the Node standard library.

> Node allows native addons in packages via the N-API so any native module aren't restricted by those permissions. (...) Node permissions (...) just restrict the Node standard library. So what? That's clearly laid out in Node's documentation. https://nodejs.org/api/permissions.html#file-system-permissi... What point do you think you're making?

What is the point of a permissions system that can be trivially bypassed?

Re: Modern Node.js Patterns

#268
post #210

Earlier quoted context omitted.

Insane but worked well. At least we could get download progress.

You can get download progress with fetch. You can't get upload progress. Edit: Actually, you can even get upload progress, but the implementation seems fraught due to scant documentation. You may be better off using XMLHttpRequest for that. I'm going to try a simple implementation now. This has piqued my curiosity.

It took me a couple hours, but I got it working for both uploads and downloads with a nice progress bar. My uploadFile method is about 40 lines of formatted code, and my downloadFile method is about 28 lines. It's pretty simple once you figure it out!

Note that a key detail is that your server (and any intermediate servers, such as a reverse-proxy) must support HTTP/2 or QUIC. I spent much more time on that than the frontend code. In 2025, this isn't a problem for any modern client and hasn't been for a few years. However, that may not be true for your backend depending on how mature your codebase is. For example, Express doesn't support http/2 without another dependency. After fussing with it for a bit I threw it out and just used Fastify instead (built-in http/2 and high-level streaming). So I understand any apprehension/reservations there.

Overall, I'm pretty satisfied knowing that fetch has wide support for easy progress tracking.

Re: Modern Node.js Patterns

#269
post #242
post #113

Whoa, I didn't know about this: # Run with restricted file system access node --experimental-permission \ --allow-fs-read=./data --allow-fs-write=./logs app.js # Network restrictions node --experimental-permission \ --allow-net=api.example.com app.js Looks like they were inspired by Deno. That's an excellent feature. https://docs.deno.com/runtime/fundamentals/security/#permiss...

I very much dislike such features in a runtime or app. The "proper" place to solve this, is in the OS. Where it has been solved, including all the inevitable corner cases, already. Why reinvent this wheel, adding complexity, bug-surface, maintenance burden and whatnot to your project? What problem dies it solve that hasn't been solved by other people?

How would you do this in a native fashion? I mean I believe you (chroot jail I think it was?), but not everyone runs on *nix systems, and perhaps more importantly, not all Node developers know or want to know much about the underlying operating system. Which is to their detriment, of course, but a lot of people are "stuck" in their ecosystem. This is arguably even worse in the Java ecosystem, but it's considered a selling point (write once run anywhere on the JVM, etc).

Re: Modern Node.js Patterns

#270
post #245

Earlier quoted context omitted.

I think the widely-implemented terminal escape sequences are well-known at this point, but I don't see why I'd want to copy this into every project. Also, I'm guessing if I pipe your logs to a file you'll still write escapes into it? Why not just make life easier?

Arguably, using a library is also "copy it into every project".

that's needlessly pedantic. the GP is noting that it's built into node's standard library, which might discourage you from installing a library or copying a table of ansi escapes.
Post reply on HN