Live data from Hacker News

Node.js 20 is now available

nodejs.org

41–50 of 101 posts

Re: Node.js 20 is now available

#41
post #6

What is the standard web application backend framework for Node.js these days, is it Koa? As I understand it express is quite dated because of the callback structure. I have been confused recently with the moving best practices. What is the server architecture Next.js is most often plugged into?

The standard is express. I say that with some glibness, but its the only true answer: a ton of the other higher level frameworks and pluggable middlewares still rely on the core express Request/Response types. And there are a ton of higher level frameworks, if the number of distinct replies wasn't obvious.

I really like express + routing-controllers [1], if you're on typescript.

[1] https://github.com/typestack/routing-controllers

Re: Node.js 20 is now available

#42
post #6

What is the standard web application backend framework for Node.js these days, is it Koa? As I understand it express is quite dated because of the callback structure. I have been confused recently with the moving best practices. What is the server architecture Next.js is most often plugged into?

I created Server.js https://serverjs.io/ and still use it. It is a wrapper around express:

- With a bunch of middleware included and pre-configured, like body-parser, cookies, Helmet, etc. All express middleware works with Server.js

- async/await routers as expected: get('/users', async (ctx) => {...}); (ctx inspired by Koa)

- Websockets, where messages behave just as another route: socket('message', async ctx => { ... });

Re: Node.js 20 is now available

#43

Earlier quoted context omitted.

I just use the Node APIs with TypeScript.

> I just use the Node APIs with TypeScript. You write your own middleware stack, and router every time you start a new "typescript" server project? Of course not. If you're not using a third party library you're using your own framework. The Node.js API is too barebone for any serious web application.

> You write your own middleware stack, and router

That is still framework nonsense. If I wanted framework nonsense I would just use a framework.

Re: Node.js 20 is now available

#44
post #23

Earlier quoted context omitted.

I've used Koa in my last few work projects but will be either switching back to Express or moving onto Fastify for the next one. Like you mentioned, Koa does indeed feel dated. It's community never really took off, either; many of it's most popular helper/companion libraries haven't been updated in years.

I still use Koa out of habit since it was the only framework for a while that had first-class promise support. One thing nice about Koa is that it's simple, so it's timeless in that way—it's not a moving target nor does it try to do something that needs a lot of core maintainers.

Yes, whole koa is like what 400 LoC?

Re: Node.js 20 is now available

#45
post #6

What is the standard web application backend framework for Node.js these days, is it Koa? As I understand it express is quite dated because of the callback structure. I have been confused recently with the moving best practices. What is the server architecture Next.js is most often plugged into?

[dead]

I’m working on a moderately large-scale Nest.js project and deeply dig it, but I don't really see a lot of people talking about it, which gives me concern.

Glad to hear you say that, though, maybe I’m just out of the loop.

Re: Node.js 20 is now available

#46
post #6

What is the standard web application backend framework for Node.js these days, is it Koa? As I understand it express is quite dated because of the callback structure. I have been confused recently with the moving best practices. What is the server architecture Next.js is most often plugged into?

Who cares how old something is, if it works well, why not use it? You can easily avoid callback-hell by making the callback you pass in to expressjs async and use await inside of it, without much drawbacks. Just because the first closure into express is a callback doesn't mean you need to use callbacks everywhere, just use await/generators/whatever you want in your application code. expressjs at this point is battle-…

The big problem is Express code like the following will either hang the HTTP request forever (--unhandled-rejections=warn), until the client times out and gives up, or crash your whole server, taking down any other HTTP requests in progress (--unhandled-rejections=throw):

  const db = {
    async getUsers() {
      throw new Error("failed to connect to database");
    },
  };

  app.get("/", async (req, res) => {
    const result = await db.getUsers();
    return result;
  });
There are various monkey patches/wrappers you can use to make async errors work the same as sync errors, but it is easy to forget and hard to understand, especially for newbies. Many other frameworks handle async/sync errors in a more consistent way.

Re: Node.js 20 is now available

#47
post #6

What is the standard web application backend framework for Node.js these days, is it Koa? As I understand it express is quite dated because of the callback structure. I have been confused recently with the moving best practices. What is the server architecture Next.js is most often plugged into?

I think it doesn't matter that much anymore.

Express was really cool and different from what was out there at the time (at least in terms of simplicity and JS support).

But nowadays there's not a lot of difference between them. Sure, some are more ergonomic than others in certain areas but the patterns are almost the same in all of them.

Re: Node.js 20 is now available

#48

Earlier quoted context omitted.

[dead]

I’m working on a moderately large-scale Nest.js project and deeply dig it, but I don't really see a lot of people talking about it, which gives me concern. Glad to hear you say that, though, maybe I’m just out of the loop.

I have also started using it pretty recently, and haven't had too much issue finding folks talking about any issues I've run into (and either found fixes for my issue, or at least workarounds while folks are currently working on fixes).

However, it still by default uses Express under the hood, though you can change that to Fastify or whatever else you like.

Re: Node.js 20 is now available

#49
post #46

Earlier quoted context omitted.

Who cares how old something is, if it works well, why not use it? You can easily avoid callback-hell by making the callback you pass in to expressjs async and use await inside of it, without much drawbacks. Just because the first closure into express is a callback doesn't mean you need to use callbacks everywhere, just use await/generators/whatever you want in your application code. expressjs at this point is battle-…

The big problem is Express code like the following will either hang the HTTP request forever (--unhandled-rejections=warn), until the client times out and gives up, or crash your whole server, taking down any other HTTP requests in progress (--unhandled-rejections=throw): const db = { async getUsers() { throw new Error("failed to connect to database"); }, }; app.get("/", async (req, res) => { const result = await db.…

Already fixed in Express 5 (which is technically still in beta, but that just seems to be the maintainer being very conservative about a major release): https://expressjs.com/en/guide/error-handling.html

> Starting with Express 5, route handlers and middleware that return a Promise will call next(value) automatically when they reject or throw an error. For example:

> app.get('/user/:id', async (req, res, next) => { const user = await getUserById(req.params.id); res.send(user) })

> If getUserById throws an error or rejects, next will be called with either the thrown error or the rejected value. If no rejected value is provided, next will be called with a default Error object provided by the Express router.

Re: Node.js 20 is now available

#50
post #6

What is the standard web application backend framework for Node.js these days, is it Koa? As I understand it express is quite dated because of the callback structure. I have been confused recently with the moving best practices. What is the server architecture Next.js is most often plugged into?

Many actively developed backend/backend for frontend frameworks like NestJS, Apollo Server, tRPC, GraphQL Yoga, etc. offer an additional layer of abstraction that typically relies on ExpressJS (or at least offer building on top of it) when deployed against Node.js, but they allow for deployment to other targets like serverless
Post reply on HN