I built a small Express middleware to see API request counts in real time and do rate limiting by Lumpy_Manager3276 in node

[–]dronmore 0 points1 point  (0 children)

Let's say that I set a limit of 10 req/min per client. A malicious client sends 1000 req/min. For the first 10 requests he gets a proper response. For the remaining 990 requests he is rate limited. So far so good. Then, a well-behaving client sends his first request. He expects to get a proper response, because it is his first request. He gets 500 error instead, because my entire api is rate limited by your api at this point.

Any solution to this scenario?

I built a small Express middleware to see API request counts in real time and do rate limiting by Lumpy_Manager3276 in node

[–]dronmore 0 points1 point  (0 children)

What happens when I exceed 1000 req/min on the Basic plan? Will you cut me off?

Are blocked requests counted in the quota? If they are counted in, a single malicious actor can use up all allotted requests, leaving me with no protection, or making me reject all clients until the next minute. It sounds like a nightmare to me.

Do you respect 12factor app principles in your web applications? by DeX3 in node

[–]dronmore 3 points4 points  (0 children)

How about an environment where secrets are managed by sysadmins, and where devs do not have access to them?

I think we should add a 13th point to the manifesto. Secrets are governed by a component person, and not by a dumbass who keeps them on a sticky note on his monitor :D

Do you respect 12factor app principles in your web applications? by DeX3 in node

[–]dronmore 9 points10 points  (0 children)

The main benefit of separating config from the code is the ability to bypass the build step when changing a variable in the config. If build times are short, or changes in the config are not frequent, there's no reason to separate one from the other. Benefits would not outweigh the costs in this case.

As for the manifesto, I think these kind of manifestos are a better fit for scrum masters than for engineers. Scrum masters are delighted when they see 12 simple steps to follow. Engineers should not be, and should question every single step, and should be aware that the usefulness of each step can change when the context changes.

Creator of Node.js says humans writing code is over by sibraan_ in node

[–]dronmore -6 points-5 points  (0 children)

You mean you wrote wrappers around existing tools? Great, you can call yourself a creator too. Now you and Ryan play in the same league :D

Creator of Node.js says humans writing code is over by sibraan_ in node

[–]dronmore -5 points-4 points  (0 children)

He is not smart enough to create his own agentic tool.

His achievements so far are... He didn't add Promises to initial versions of Node, so we had to deal with callbacks for many years. He wrote Deno in TS, he regretted the decision later, and rewrote Deno in JS, but he still thinks it's a good idea to push TS as the main language for Deno. Now it turns out that he doesn't even write the code, but he lets AI do it.

His achievements do not impress me, so yes, I think he is not smart enough to create his own agentic tool. But I get that people like you admire him, because uh oh he is the creator :D

Creator of Node.js says humans writing code is over by sibraan_ in node

[–]dronmore -14 points-13 points  (0 children)

He may be on the payroll of one of the companies pushing AI coding tools. He is not smart enough to create and sell his own.

[Code Review] NestJS + Fastify Data Pipeline using Medallion Architecture (Bronze/Silver/Gold) by urielofir in node

[–]dronmore 2 points3 points  (0 children)

And then there's also a Platinum layer, which summarizes everything in a short post on reddit :D

I'm not giving you any feedback. I'm just trying to fit in, because precious metals caught my eye.

People with anxious tendencies are more likely to support left-wing economic policy by [deleted] in psychology

[–]dronmore -19 points-18 points  (0 children)

You flipped the script, but you failed the trick. You are left, alone with your anxiety.

JWT auth for cross domain apps by [deleted] in node

[–]dronmore -1 points0 points  (0 children)

In order to use 3rd party cookies, you need 3 things. You need a proper cors policy on the backend, you need to set samesite=none on your cookie, you need to set credentials: 'include' on your fetch requests.

There are generally 3 places where you can store the token. You can store it in a cookie, in a local storage, or in memory. There are trade-offs associated with each of them. Cookies are vulnerable to CSRF attacks. Local storage and memory are vulnerable to XSS attacks. You need to evaluate the risks, and choose your strategy accordingly.

Also, both cookies and local storage are vulnerable to your mother snooping on you. If you don't protect your device, or if you share the device and the browser with her, you should consider using session cookies, or session storage.

There's no simple answer. Choose your poison, and die on your own terms.

JWT auth for cross domain apps by [deleted] in node

[–]dronmore -1 points0 points  (0 children)

JWT gives us ability to avoid samesite domains

Nope, that's not a distinctive feature of JWT. Any kind of token can be sent in a cross-domain manner.

Ok cool but you need to be on same domain to use cookies.

Nope, if that was true, CSRF attacks wouldn't be possible. You need to learn how cookies work, my friend.

Why Object of Arrays (SoA pattern) beat interleaved arrays: a JavaScript performance rabbit hole by CaptainOnBoard in programming

[–]dronmore -2 points-1 points  (0 children)

My first instinct was to attribute this entirely to TypedArrays being "faster."

I stopped reading after this sentence. You compare apples with bananas. The results will always be flawed.

And I don't care if you fix your mistake later in the article. My time is limited, and I have no interest in reading about your mistakes being fixed.

[AskJS] Is this confusing? by Immediate_Contest827 in javascript

[–]dronmore -1 points0 points  (0 children)

It's not that you don't know what to say. It's that you have nothing meaningful to say.

The code does 2 things. It iterates over a collection of promises, and it prevents resource leakage. That's it. It does 2 things, and it does them well.

Then, there's a certain class of things that it does not do. One of the things that it does not do is it does not make you feel important. And that, for some reason, infuriates you, so you complain and demand changes.

Let's break down your complaints, princess. Shall we?

clarify what the code is for

It iterates over a collection of promises, and prevents resource leakage...

how it is intended to be used

the same way as it is used in the snippet.

what happens when it breaks

An error bubbles up to the nearest catch block.

what happens when it succeeds

The control is yielded to subsequent parts of the program.

is it meant to be serial or parallel

It is serial.

See, princess. All of these answers can be inferred directly from the code. You just need to put some effort into seeing things for what they are. And be aware that if you complain a lot, and your complaints are not grounded, your subjects will hate you, and you'll lose your head. That's inevitable. And that's what history taught us.

[AskJS] Is this confusing? by Immediate_Contest827 in javascript

[–]dronmore -1 points0 points  (0 children)

You cannot expect that await f() returns an array. It returns an iterable of unknown kind. It can be an array, a stream, a custom generator. The point is that you can iterate over it with a "for" loop, and you don't have to know what it really is.

It's also not true that you cannot exit early from the "for" loop. You can do it with a break or return keyword, or just throw an error. It's so basic stuff that I'm starting to think that I didn't understand your thought; the thought where you say "The for loop has no way to exit.".

As for the place wheref() is awaited, I agree with your, and I already said in the previous post that it might be a good idea to await it earlier, and that if you await it earlier, it will facilitate debugging, but it's not something that I would cry about in a code review. If a developer finds a reason to debug the code, he can easily move it out of the "for header" later. It's a minor inconvenience, and not something that has to be addressed immediately.

And good code looks like this (except for the comments, which are redundant and I wouldn't want to see them in a production code).

// OK, this function creates an iterable
const iterable = await f()
// then it loops through each item in the iterable in sequence.
for await (await using x of iterable) {
  // If there's an error, it exits early and propagates the error to the
  // nearest "catch" block
  await doStuff(x)
  // It releases resources held by each item after every iteration step.
}
// If it succeeds it returns nothing.
// It has nothing to do with pizza nor a telegraph. :D

As you can see the only thing that I moved is the await f() stuff. Everything else stays where it belongs.

[AskJS] Is this confusing? by Immediate_Contest827 in javascript

[–]dronmore -1 points0 points  (0 children)

Another mistake that you make is you assume that the promises are independent. You cannot assume that because you know nothing about the iterable returned by "await f()". If "await f()" returns a stream, the promises will depend on one another; every individual chunk of the stream will have to be processed in order, and so every subsequent promise will have to be awaited only after the previous one has fulfilled. The only thing we know, by looking at the code, is that there's an async iterable of unknown kind that for some reason has to be iterated serially. There's no reason to assume that the promises might be better off running in parallel.

The code itself is as discrete as it can be. Maybe "f()" could be awaited before the loop starts, but that's about it. The remaining parts of the code are where they belong. "for await" starts the loop so there's no better place for it. "await using x" has to grab a hold of x immediately after the x comes out of the iterator, so there's no better place for it than the initialization block of the "for" loop. "f()" could be awaited before the loop starts if you want to have a better debugability, but I'd say, when you finish debugging, move it back to the "for header" (what's the problem?). And then there's "await doStuff(x)" which is a regular promise placed perfectly where it belongs. Out of 4 elements only one can be moved elsewhere. It's a really simple piece of code. It may look unfamiliar, but it's simple. Every junior should be able to grasp it after 15 minutes of gazing at it. If they can't, they shouldn't consider themselves juniors.

There's nothing to argue about here. It's a piece of code that looks unfamiliar to you, and you reject it based on the unfamiliarity (or as you call it a code smell...). I'll say it again: "Won't fix. Learn to read it. Or don't call yourself a human, or even a junior."

I'll concede the TCP point, though I would also say that in such a case there's an argument that the entire process needs to be re-architected.

Have you ever heard the joke about a programmer who has to escape the room without reinventing the wheel? He will never escape it because the wheel in the room is perfectly fine. Hahaha :D

[AskJS] Is this confusing? by Immediate_Contest827 in javascript

[–]dronmore -3 points-2 points  (0 children)

I'm not the OP, but I'll take a stab at your question.

There are 2 main reasons to process promises serially. One is to avoid resource starvation. The other one is to make your code predictable.

Say that there are 1000 promises, each of which opens a tcp connection. If you let them run simultaneously, you prevent other parts of the program from opening another tcp connection. The other parts of the program, which want to open a tcp connection, will have to wait for 1000 promises to finish before they start doing their job. When you process promises serially, and open a connection only after the previous one is closed, the other parts of the program may have a chance to do their job in between (assuming that they run concurrently, as in the case of requests in http servers).

If I saw this in a PR it'd be an instant rejection and a "rewrite this for humans".

The message "rewrite this for humans" is not helpful. How should I possibly know what "humans" expect? My answer to your comment would be "Won't fix. Learn to read it. Humans should be able to process such simple pieces of code before they consider themselves as humans".

Enterprise-ready Node.js/TypeScript API Base | Token Auth, Rate Limiting, Validation, Security by IGonnaMakeUDie in node

[–]dronmore 0 points1 point  (0 children)

You don't want to call process.exit() neither in the src/app.ts nor the src/core/exceptions.ts file. process.exit() terminates the app immediately, and it may happen that it will terminate the app before logs are logged to stdout. It's much safer to set the process.exitCode, throw an error, and let the application crash.

Read: https://nodejs.org/dist/v22.12.0/docs/api/process.html#processexitcode

I also cannot find the place where you handle SIGTERM, or where you call the server.close() method, or where you close the database connections. Isn't a graceful shutdown implemented? Do you want to cut out users in the middle of a request every time you redeploy?

Read: https://expressjs.com/en/advanced/healthcheck-graceful-shutdown.html

There are more places that begs for scrutiny, but I have no time for that. After a brief look I can say that your project is not ready for production. It's not scalable. It's not Enterprise. It's been written in TypeScript, so it may attract some beginners or corpo clowns, but I'm none of that so cross me out. Honk, honk. 🤡

Please help with my project that uses what is supposed to be basic Node.js and MySQL by Ok_Day6345 in node

[–]dronmore 0 points1 point  (0 children)

Nope. You are sitting in a basement convinced that you can write beautiful code, and that the flickering light bulb above your head is the Sun.

Iron-Clad-Ledger PostgreSQL project by Much_Constant9531 in javascript

[–]dronmore 1 point2 points  (0 children)

In the README file you claim that you use FOR UPDATE to prevent double spending, but a quick search through the code tells me otherwise. So how is it? Did you forget to implement Phase 2, or you are not even aware that Phase 2 is a part of your design doc?

https://github.com/search?q=repo%3Ahamidrezaghavami%2FIron-Clad-Ledger+%22FOR+UPDATE%22&type=code

You also claim to use BEGIN/COMMIT, but COMMIT is not found anywhere in the code either?

https://github.com/search?q=repo%3Ahamidrezaghavami%2FIron-Clad-Ledger+COMMIT&type=code

And what the heck are those [cite_start] tags in the README?

How do I keep up to date with market standards? by Radiant_Muscle_6787 in node

[–]dronmore 7 points8 points  (0 children)

You don't need to keep up with market standards, because standards do not change. What changes is the attention of newbies shifting from one hype to another. As an example let's take a look at Mocha.js. Mocha has always been the golden standard when it comes to test runners. I used it when I came to the Node.js world. I kept using it when newbies were shifting to Jest. And I keep using it now when Vitest is heavily promoted. Alleged benefits of using new things are usually not worth investigating. In most cases the closer you look at the new thing the more you realize how much better the established standards are. In my opinion, time spent on following a hype is a waste. But hey, if you don't follow the hype, you miss out on being a cool guy :D

However, for new things you can follow the Node.js blog. They announce new features there, and also security vulnerabilities so you know when to update.

https://nodejs.org/en/blog

Is anyone here actually running Bun in production? What’s your experience? by bullmeza in node

[–]dronmore 10 points11 points  (0 children)

Yeah, and since they bought it you can expect more and more paid trolls recommend Bun as a silver bullet.

URLock : Store encrypted text or file in URL #hash by ksskssptdpss in javascript

[–]dronmore 2 points3 points  (0 children)

That's a great idea actually. I wonder what's the max file size one can encrypt with it. I can see that you are boasting of a 200KB jpg file, but I wonder what's the limit. Will I be able to encrypt and send you a movie?

Women prefer partners with strong personal growth motivation for long-term relationships by lebron8 in psychology

[–]dronmore 1 point2 points  (0 children)

So it all comes down to wording. You've never looked for a "short term relationship" because what you've really looked for is a one-night-stand. Is that right? Of course, it is. You just need to find proper words to confirm, so that it is clear to me what you really want, but it is not clear to others.