r/javascript • • 19h ago

Typescript/React

Thumbnail github.com
0 Upvotes

How to make this game better ?


r/javascript • • 23h ago

A New Node.js library

Thumbnail npmjs.com
0 Upvotes

When you scale a Node.js backend using node:cluster, you run into a surprisingly annoying problem:

How do you rate-limit external APIs like Stripe or OpenAI while making sure all workers share the same rate limit?

The first solution that comes to mind is usually: "Just use Redis."

But does it really make sense to introduce additional infrastructure complexity, network overhead, and an entire external dependency just to coordinate a few API calls coming from the same server?

That's exactly why I built cluster-rate-limiter.

A Node.js library that gives you coordinated rate limiting across workers, powered entirely by Node.js's native IPC messaging, with no Redis and absolutely zero external dependencies.

Rather than diving into the internals here, here's what you get out of the box:

  • Zero Setup: Install it and start using it. No additional infrastructure required.
  • Developer-Friendly API: The run() method accepts your fetch call or any function directly, along with all its arguments. No complicated callback patterns.
  • Two Types of Limits: Supports both Semaphore-based concurrency limits and Duration-based rate limits for enforcing strict time windows, such as those imposed by Stripe APIs.
  • Typed Errors: If a request times out waiting for permission, the library throws a clear, specific error that you can easily translate into an HTTP 429 Too Many Requests response.

And when it comes to performance, the core data structure for tracking request timestamps uses a zero-allocation approach built around a Float64Array ring buffer.

This eliminates the need for repeated array reallocations and significantly reduces garbage collection pressure under heavy load.

If you're interested in the low-level details, I've explained the ring buffer implementation and how it reduces memory overhead in the README.

If you're running a clustered Node.js backend and want to avoid the overhead of introducing Redis just for rate limiting, check out the links below, explore the architecture, and let me know what you think!


r/javascript • • 6h ago

I've proven that you don't need quotes or parentheses in JavaScript

Thumbnail blog.ikaes.de
50 Upvotes

You can overwrite the prepareStackTrace property of the Error object by String prototype's functions and invoke them without parentheses. Then by overwriting the Error and Array prototype it is possible to control the arguments. Combining this behavior, together with some JSFuck-inspired tricks, it is possible to generate arbitrary JavaScript strings and run arbitrary JavaScript with only letters + - = and ,


r/javascript • • 4h ago

penciled – persistent text highlights/notes with the CSS Custom Highlight API (no DOM wrapping)

Thumbnail penciled.org
5 Upvotes

I built penciled, a small MIT library for persistent text highlights and notes in the browser. It uses the CSS Custom Highlight API instead of wrapping ranges in <span>s, so the DOM stays intact and layout/selection quirks are milder. Anchoring tries to survive edits when you come back to the page.

npm: penciled
GitHub: https://github.com/marcellosso/penciled

There's also a companion browser extension (same engine) if you want highlights on arbitrary sites, happy to answer questions about the API or the anchoring approach.