Express.js alternative built on top of uWebSockets.js #137
Replies: 24 comments 23 replies
-
@zaiste your idea is very good. In my case I made an alternative based not only on express.js but also on the facilities of zeit/micro, koajs and fastify. Came up with the idea of creating @fearlessjs but is still in beta with some things not yet well defined for production. I believe we had similar ideas but in different contexts |
Beta Was this translation helpful? Give feedback.
-
Exciting! |
Beta Was this translation helpful? Give feedback.
-
@rodrigooler thanks for the kind words! Just to clarify, this project is not « based » on Express.js, it's just an alternative with a relatively different API. Your project looks similar, indeed. I've just glanced the project, but it seems you're focusing on the server-side only. De qualquer forma, otimo trabalho! :) @Annihil it's very similar to sifrr. I prefer, however, a single package approach. Many separate, independent modules sounds good only in theory; in practice, it is difficult to manage such projects imho. |
Beta Was this translation helpful? Give feedback.
-
Nice project! Too bad it's monolithic and comes with Vue, a back-end only package would have been awesome 😕 |
Beta Was this translation helpful? Give feedback.
-
@Annihil Here's just the core engine of Huncwot. I've extracted it to a separate package. I also plan to remove Vue.js soon, and to replace it with something like Svelte, so it compiles the UI to a minimal set of JavaScript instruction and there is no need to include the run-time in the app bundles. |
Beta Was this translation helpful? Give feedback.
-
@zaiste You should be careful with your dependencies. You take uWS build from scratch with speed in mind and than use a lot of proven to be slow packages like bluebird... It will mitigate sole purpose of using non standard, but fast server |
Beta Was this translation helpful? Give feedback.
-
@slavaGanzin that's a good point! Please consider it work-in-progress. I focused on making something that works in first place; hopefully the improvement will follow. Feel free to join the venture ;) |
Beta Was this translation helpful? Give feedback.
-
Hello Zaiste, This is a big post. I'm trying to dissect it:
setYield can definitely be wrapped up, no problem there in fact it should have been.
This is supported, see examples?
Some parts are still missing, like receiving chunked encoded data but other than that the user should take care of whatever data you get. Json or anything, multi-part or whatever is up to the user to implement.
These are, at best, suitable as examples. File upload / serving is an abstraction over this library that is up to the user. |
Beta Was this translation helpful? Give feedback.
-
Just FYI, sifrr-server doesn't change uws's API in any way (no middleware), it just builds functionalities you mentioned on top of it without affecting any other parts/performance where it can. So there is not really any learning curve if you know how to use uWS.
Also mentioning that you prefer single package approach as opposed to sifrr is not really related to this discussion IMO, as this issue only discusses about sifrr-server, which is a single separate library/project/package. Not related to this issue, but In my experience maintaining them in one monorepo has saved me a lot of time (because of my own structure though, if I had chose to build in a different way, maybe separate repo approach could have been better) |
Beta Was this translation helpful? Give feedback.
-
I appreciate your response!
Great! I'm still in the process of revising my C++ knowledge. I hope to help out either with this or upcoming challenges.
Yes, I've phrased that wrongly. My intention was to point out the easy of use from the consumer side, i.e. you can directly use either sync or async handler, without additional steps i.e. explicitly adding
Yes, I'd also prefer to keep uWebSockets as simple as possible here. I've decided to wrap by default for additional convenience to the end-users. By the way, is there a particular reason why |
Beta Was this translation helpful? Give feedback.
-
I was indeed wondering the same 😄 I do believe we need a decent wrapper to ease the use of uWS.js, for now it's mostly a replacement of the In the meantime, since GraphQL popularity is rising, I went ahead and created µGQL, a very basic replacement of express-graphql but using uWS.js. |
Beta Was this translation helpful? Give feedback.
-
@Annihil https://github.com/sifrr/sifrr/tree/master/packages/server/sifrr-server#graphql-server 😂 |
Beta Was this translation helpful? Give feedback.
-
@aadityataparia yes I'm fully aware of that! |
Beta Was this translation helpful? Give feedback.
-
@Annihil Sounds awesome, I will try to contribute some improvements too :) 🚀 Also since it works with uWS, it will also work with sifrr-server :P |
Beta Was this translation helpful? Give feedback.
-
how would it be possible to implement gzip compression for the http/https response ? |
Beta Was this translation helpful? Give feedback.
-
@arputcu you can use zlib to compress, see https://nodejs.org/api/zlib.html#zlib_zlib_gzip_buffer_options_callback |
Beta Was this translation helpful? Give feedback.
-
@Annihil I also few days ago made own GraphQL Server powered by uWebSockets.js with GraphiQL, Mutation, Variables support. But i trying to make |
Beta Was this translation helpful? Give feedback.
-
@dalisoft I haven't looked at it yet, seems a bit challenging indeed. |
Beta Was this translation helpful? Give feedback.
-
@Annihil Oh, i built it for my own needs, not for challenging. Who needs, uses as yours. |
Beta Was this translation helpful? Give feedback.
-
I also built own Express.js alternative and made API very similar to Express.js. You can see my library here |
Beta Was this translation helpful? Give feedback.
-
If you guys use GraphQL, you might as well use Socket.io too in terms of performance. GraphQL has to:
Anything else? I don't think Node is particularly good at any of these things. And for what? So that you could now have huge technical debt (both client and server side), N+1 and caching problem to solve, quite complex throttling and query depth protection to implement, etc. Trust me, you don't have the same problems as Facebook does, you don't need GraphQL and this comes from someone who started his dev career with GraphQL and was like a cult member. Don't take this too seriously, I'm just bitter that it took me several years to realise that I'm 10x better off without it. |
Beta Was this translation helpful? Give feedback.
-
GraphQL is good as a declarative language for description interfaces, we describe database models and structures for request/response . At the start of the service, we compile GraphQL into optimized JS functions and simple JS objects. GraphQL like TypeScript, for only compile time, not runtime. |
Beta Was this translation helpful? Give feedback.
-
No, we use REST API (cached method GET, for mutation PATCH method) |
Beta Was this translation helpful? Give feedback.
-
@zaiste Wow didn't know someone already implement this idea, i'm creating this feature without read another discussion except #483 and implemented as utilities for sifrr-server on private project at my company. I think my version was little bit simple than yours, just add some feature that i think useful for separating logic app.use(fn1, fn2, fnN); // for adding global middleware
app.use('/profile', fn1, fn2, fnN); // for adding scope middleware I like that express have ability for stacking handler / middleware, so create same ability for the sake of convenience, also add interceptor into create request method for applied those ability, well i think same that you mentioned above app.get('/profile', fn1, fn2, fnN); and with result that global and scope middleware executed first, and last the stack of handler on http request method |
Beta Was this translation helpful? Give feedback.
-
I'm working on a high(er)-level wrapper on top of this (fantastic) project. It is a response to a few recent requests/questions I stumbled upon here to incorporate features like middlewares, static file handling or request body parsing out-of-the-box, right in uWebSockets.js - in short functionalities that usually come with Express.js.
Some of them were marked as
wontfix
(which is totally understandable). I'd like to fill in this gap with some higher level abstractions and potentially help out uWebSockets.js to keep its focus.Also, in one of the recent issues (#81) @alexhultman said:
@alexhultman please feel free to close this issue if you think it doesn't belong here. My goal was to help out with the issues I reference below.
My project is called Huncwot, it builds on top of uWebSockets.js and it provides:
request
andreturns a
response
(in response to Error: Returning from a request handler without responding or attaching an abort handler is forbidden! #45)For example, you can validate the body of the incoming request using built-in
params
helper:For the completeness, it needs
setYield
to be implemented in uWebSockets.js(cf. #31 (comment))
support for async functions out-of-the-box (cf Is it possible to use asynchronous functions in/as http handlers? #50)
built-in request body parser (in response to Congrats + body parser #64 and Need getHeaders() #70). It automatically extracts the method, headers, cookies and params (either request body, dynamic routes or query params)
Using HTTPie:
This returns
params
as{ name: 'uws', person: 'alex', a: '1', b: 2 }
built-in file upload (cf. Handling multipart/form-data body #106)
static file handling (cf. How do you serve static files properly. #110)
My goal is to keep it tightly integrated with uWebSockets.js and adapt according to
uWebSockets.js' vision.
Also, I share a bit of similar mindset as Alex. This is an alpha project. I do it for fun. It got me even motivated enough to refresh my C++ ...after 15 years. ;) I hope you will enjoy it, but please use it at your own risk - it's not production ready. I won't be able to support you.
Beta Was this translation helpful? Give feedback.
All reactions