7 ms·
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 stru
by icpmacdo 3y ago
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?
- greenbeard 3y agoExpress is still fine to use. To me it's either express or fastify. A lot of opinions in the JS world.
- super256 3y agoThis. Fastify is so great. Unfortunately, the documentation became worse after v2 because Matteo was too laissez-faire in approving new doc contributions. Imo the docs need a major re-write, beginning at "getting started". New users don't know whether they should use "fastify-cli gen", "npm init fastify" or copy manually from the "getting started"-guide. And people also tried to push their fastify-plugins to the top of the plugins-site by adding a "@username" for every plugin: https://i.imgur.com/hHyI6JO.png https://i.imgur.com/hHyI6JO.png (left are the old docs, right are the current docs where ppl try to game the system). Also, fastify-cli needs to rework the custom options in typescript projects imo. Ok, that's all. Other than that, fastify rocks!
- sideproject 3y agoI've used this - https://adonisjs.com/ https://adonisjs.com/ - I don't think it's "standard". Is there such a thing? I guess Express was a de-facto standard. I'm a bit biased since I come from Laravel background, so adonis feels familiar.
- tannhaeuser 3y agoExpress (fka Connect) is standard in the sense that the "middleware" API design was/is part of the CommonJs server-side JavaScript (SSJS) initiative [1] from which Node.js originated and insofar as you can write a middleware that plugs into Node.js' core http API and express.js at the same time since these invoke your code using the same basic callback, which was deemed desirable for portability back when Node.js wasn't the only SSJS framework around. Express/connect draws inspiration from Ruby's Sinatra/Rack and Python's WSGI, and is based on JSGI/JackJs. [1]: https://wiki.commonjs.org https://wiki.commonjs.org
- austin-cheney 3y agoI just use the Node APIs with TypeScript.
- throw_m239339 3y ago> 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.
- Scarbutt 3y agoHe is hardcorezz
- austin-cheney 3y ago> You write your own middleware stack, and router That is still framework nonsense. If I wanted framework nonsense I would just use a framework.
- capableweb 3y agoWho 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-tested, minimal, easy to understand (both in usage and internals) and have a huge community still. It's very mature and does what it does well.
- tshaddox 3y ago> 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. I thought this was slightly awkward due to error handling, but it looks like Express 5 (in beta) supports async callbacks natively.
- aobdev 3y agoI'm sorry to point out that the first 5.0 alpha came out in 2014 and still hasn't been released. When people talk about the ecosystem/battle-tested-ness/quality of express I think that unfortunately doesn't extend to anything other than the latest major on npm. It's not "modern" but it's still a good tool.
- cantaloa 3y agoI haven't used Express in ten years, but imo `async (req, res, next) => ...` would mainly be attractive if failure was automatically handled and you could `await next()` to post-process the response. Though it would still help you write async code inside that route. Since iirc you send responses directly from handlers in Express, I'm not sure the latter is possible even with express-promise-router since you basically need downstream routes/middleware to return a Response object rather than send it directly. I think Express is never going to unify with Koa's direction since it's just too disruptive to Express' ecosystem (the v5.x branch is stale) which is probably for the best.
- patdx 3y ago
- bnb 3y agoKoa is relatively outdated at this point. Fastify is generally what I and most people I know look towards when starting something "new". Express is still in a lot of things, though.
- nailer 3y agoNot sure why this is downvoted, Fastify is quite popular and the 'generator for everything' approach of Koa didn't really take off. Architect serverless (https://arc.codes https://arc.codes) is pretty good for serverless.
- EthicalSimilar 3y agoI’m a fan of hyper-express, built on top of uWebSockets with an api similar to express - https://github.com/kartikk221/hyper-express https://github.com/kartikk221/hyper-express
- spankalee 3y agoKoa's great, and I use it for just about every server. It's simple, fast, supports async middleware great, and has a big middleware ecosystem.
- siquick 3y agoYou can get pretty far with Next API routes as a replacement for a seperate Express backend. https://nextjs.org/docs/api-routes/introduction https://nextjs.org/docs/api-routes/introduction
- edgyquant 3y agoI’ve been using this and deploying straight to vercel (where they run as serverless functions.) Took some obscure googling to get things like sequelize to work, not overall it seems to work pretty great. However I would like to be able to control the resources (e.g. adding more cpu etc) and haven’t yet found a way to do so.
- leerob 3y agoYou can configure some knobs, like `memory` and `maxDuration`: https://vercel.com/docs/concepts/projects/project-configuration#functions:~:text=including%20its%20version.-,memory,).,-maxDuration https://vercel.com/docs/concepts/projects/project-configurat...
- skramzy 3y agoI'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.
- cantaloa 3y agoI 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.
- mirekrusin 3y agoYes, whole koa is like what 400 LoC?
- skwixusu 3y agoExpress. Same as it’s ben for a decade.
- GarryOne 3y ago[dead]
- Eric_WVGG 3y agoI’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.
- DanHulton 3y agoI 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.
- Zealotux 3y agoI'm using it for my side project, a highly productive framework; I can also say it's in use in some _very_ large corporations, although I cannot give details about that.
- creatonez 3y agoI can't tell how this has actually improved upon existing options like Koa. This reeks of object oriented programming just for the sake of object oriented programming.
- remify 3y agoThe idea was to use the same paradigmes and practices as the Angular framework. It's nice to have consistency between backend and frontend, but it is indeed a bit heavy and really not necessary most of the time.
- nailer 3y agoOdd. Most people I know are trying to avoid OOP, particularly in the JS community.
- lucideer 3y agoCallbacks in JS aren't really dated, just many of the patterns associated with them are. The Promise constructor itself takes two callbacks as its arguments. Async/await are just syntax sugar over that constructor. Express supports promise-based mw callbacks just fine. So I'd still say Express is the main choice. Personally I've never loved the Express API as it encourages a lot of heavy mutation (Koa does too), so I tend to be on the lookout for good alternatives - I haven't seen any that seem to be sticking (gaining significant enough community to bet on) more than Express. There's a few things like Next/SvelteKit that cover all bases in one, from your web app backend -> SSR frontend -> client states, but if you're looking at pure backend for e.g. an API, Express is still going strong.
- knapcio 3y agoIn the past 3 years I've built 4 apps (1 mid-size, 3 small-mid) using Apollo and IMO it's currently the best possible approach. I did a research for my latest app a half year ago looking for sensible alternatives and didn't really find any.
- Scarbutt 3y agoYou can use this small lib for expressjs https://github.com/express-promise-router/express-promise-router https://github.com/express-promise-router/express-promise-ro...
- paxys 3y agoLack of async support in middleware makes Express a non starter these days. Koa, Fastify, AdonisJS, Hapi, Nest are all great.
- 015a 3y agoThe 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 https://github.com/typestack/routing-controllers
- franciscop 3y agoI created Server.js https://serverjs.io/ 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 => { ... });
- hugozap 3y agoI 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.
- jhanschoo 3y agoMany 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
- r3trohack3r 3y agoWhen standing up a server I reach for fastify. The only exception is when I’m working inside an established Node shop where they already have a prolific framework, I’ll reach for what they already have in that case to avoid fragmenting their stack. Almost always, that’s express. fastify is performant, thoughtfully designed, and well architected.
- bastawhiz 3y agoKoa works great. The nicest part is that you don't feel like you're fighting Typescript when you use it, if you use static types.
- princevegeta89 3y agoAdding to this, these days, what's a complete nodejs MVC web framework that allows for easy integration of something like server-sided React for the front-end?
- Jarwain 3y agoFor anything CRUD or that can be modeled as such, I use FeathersJS (https://feathersjs.com/ https://feathersjs.com/). Real time updates are basically free, db integration is easy and adaptable. The service-oriented architecture with hooks just feels like a very natural way to think about an application. They recently pushed their long awaited v5 update, which adds a Koa transport alongside the historic express transport, and improves the "code reuse between client & server" story for schemas/models/types.
- elforce002 3y agoExpress + typescript. Simple. Powerful. Battle-tested.
- kamilafsar 3y agoI personally hate the TS bindings. That's one of the reasons that drove me to create Phero: https://phero.dev https://phero.dev
- Chyzwar 3y agofastify https://www.fastify.io/ nest.js https://nestjs.com/ hapi.dev https://hapi.dev/ All are better than express.js. It is annoying that express is still go to for many where its ecosystem is pretty dead.