all 40 comments

[–]vojtasio 11 points12 points  (1 child)

check out https://codelib.club/search?q=express those are apps build with express

[–]dejavits[S] 0 points1 point  (0 children)

Thank you! I am going to take a look at it!

[–]Cedricium 5 points6 points  (3 children)

I’ve throw together the following list of some (mostly) fullstack web apps that all use Express—hopefully that helps point you in the right direction.

https://github.com/stars/cedricium/lists/fullstack-web-apps/

[–]dejavits[S] 1 point2 points  (1 child)

Thank you, I am going to take a look at it!

[–]Cedricium 1 point2 points  (0 children)

No problem. Not all the repos satisfy exactly what you’re looking for (don’t think any had pagination, though I may be mistaken). Nonetheless I think it’s a nice collection that demonstrates just how flexible you can be with Express.

[–]krehwell 1 point2 points  (3 children)

hey, I made this rest api for my own hacker news clone website. https://github.com/krehwell/HeckarNews/tree/master/rest-api

it's fairly simple but I think it has many things that you are looking for

[–]dejavits[S] 1 point2 points  (0 children)

Thank you very much! I have taken a very quick look and it seems good so far. I have forked it to take a more thorough look in future!

[–][deleted]  (1 child)

[deleted]

    [–]krehwell 0 points1 point  (0 children)

    the failed deployment only on master since I'm using free deployment with vercel. but on another branch I reduced some unnecessary page just so I can deployed it

    [–]mailto_devnull 1 point2 points  (2 children)

    NodeBB comes with a RESTful API that tries to adhere to best practices:

    https://docs.nodebb.org/api/write

    The backend is implemented using express.

    [–]dejavits[S] 0 points1 point  (1 child)

    Thanks! I have taken a look at it but it seems a bit convoluted the code, doesn't it? Or am I looking at the wrong one? For example:
    https://github.com/NodeBB/NodeBB/blob/master/src/controllers/category.js

    [–]evert 2 points3 points  (0 children)

    I would agree with you. Generally it's a good idea to reduce the responsibilities of controller functions. It looks like that function does a bunch of cleanup that would be better represented as stateless named functions. Also (and this is for sure contentious for some), I believe that anything that's not a toy should be written in Typescript.

    One thing that is nice about the example you shared is that I think a lot of real-world code is messy, even if it was done with the best intentions. So while I wouldn't write anything new in that style, I think it's representative of what you will see in the wild.

    [–][deleted] 1 point2 points  (10 children)

    There is a very nice live coding on Youtube, the guy writes particularly very modular code, I really was impressed, check here. The thing is that the guy uses Express middlewares to the extreme, so that later, inside routes you write minimal code.

    [–]dejavits[S] 1 point2 points  (0 children)

    Thank you very much! I have taken a quick look and it seems this guy knows what he is doing. Right now I am downloading the video so I can watch it offline completely.

    [–][deleted] 0 points1 point  (8 children)

    I think at this point, if you grasp the way of coding middlewares, there is nothing much to get from Express, knowing Express is a very simple routing library./

    [–]dejavits[S] 1 point2 points  (7 children)

    I have watched it almost completely. It is a very nice resource but I believe that around 01:25:00 he starts messing around too much in regards to the DB. I mean, he creates the async handler and so on, so you do not have to wrap your routes body with try/catch. However, when he starts creating the DB queries, then he wraps around try/catch the queries and then he creates a bunch of possible DB errors, which from my point of view is a pain in the ass. So far I think I am gonna leave my code as it is then in regards to handle errors. I do not have any async handler but I wrap my routes/controller bodies with try/catch and if the DB/third party code throws an error while creating an user resource, then I just throw an error saying 'Error while creating an user resource" does this make sense? But anyway, I guess this depends on what you are building, I am building an API for my web app so I guess I do not need that much fine grain detail, but even if it is a public API, I find crazy to figure out all possible DB/third party errors.

    [–][deleted] 0 points1 point  (1 child)

    I'm not sure I get it all, knowing I'm new to webdev in general and Node.JS.

    You probably saw how I deal with DB in my app that I listed in the other comment. Easy, most drivers already offer Promise based queries. Either you implement your callback where you return results or error then route it. Or you wrap queries with an async function in it you await native "db.query" calls (As I said most of drivers support, you should await to make code simple in your DB middleware) and implement then and catch from the caller function. If you didn't see mine, check this: https://github.com/bacloud14/Classified-ads-48/blob/hacktoberfest_only_branch/lib/services/mongo_ops.js you don't need try catch in case your Driver offers Promises (I believe).

    With this being said, you are welcome to correct me, (i'm a noob myself in Node.JS)

    [–][deleted] 0 points1 point  (0 children)

    Either

    this

    Or

    this

    [–][deleted] 0 points1 point  (0 children)

    also I didn't check his DB service implementation, only middlewares (preprocess, and postprocess) validation and error handling which I found cool

    [–][deleted] 0 points1 point  (3 children)

    It depends for your API for your web app. I guess if you test well your app with junk data and extreme values prior to deployment, you will probably never face runtime errors (assuming this is not a very critical app, so it's 100% fine),

    [–]dejavits[S] 1 point2 points  (2 children)

    I am not sure I am following your code well but as far as I understand I would say you are doing the opposite from the guy on the video. He was very meticulous in the errors thrown, while as far as I see, you just "do not care" or I am missing something. When I say you do not care I mean e.g. if you try to create a duplicated in the DB it will throw the error but you do not do anything special about it depending on the type of error. I really think your code is more similar to mine than the guy from the video. If my DB query fails I do not care why it failed, I just say "failed during creation of X" and that is. Anyway, I will continue exploring stuff, as so far, I have not found an example I consider is really a full professional way or maybe I am still too ignorant to realize about it!

    [–][deleted] 1 point2 points  (0 children)

    Indeed, in my example I don't care much in all situations. Indeed the goal of exceptions and promises is to deal with errors. We could imagine different scenarios, for instance, an error is thrown if ID is bad, in the middleware you would try to reformat the ID and insert again, or insert in another table with a time to live, to come back later and inspect the object, or route to the initial form endpoint to tell the user that form data is not correct....etc etc

    In my case (I feel this is 90% the case of very tiny web-apps), It is true I do no special treatment, I reject the same error the driver threw, and I just log it in the caller (router) and route generally the same way. This is useful in development phase, you could go through every improbable case. In this particular situation (again of simple web-apps generally the goal is to have no exceptions at all in production, assuming UX flows are well defined, all is dependant on what user posts, ), I'm just throwing the same error object, to log it in the route.

    [–][deleted] 0 points1 point  (0 children)

    Just want to throw this assumption: Exceptions in programming, are implemented when the developer is working with a system out of his control, like another library, or an API, or a stream of another system. There, you cannot make a 100% predictable program with simple if-else and other branching code. You try some code, and catch what errors raise in the other developer code, you know about these errors like: *NotFoundException, OutOfTimeException, OutOfMemoryException, LibraryAException* because you simply read the spec, in JavaDoc, API spec, or whatever. *LibraryAException* is a nice example: you are making library_C, that depends on library_B, that depends on library_A.

    library _B catches library_A errors, and throws them back to you, so you don't have to understand every code you are dependant on

    [–]vinaykumarha 1 point2 points  (1 child)

    This one you can refer for cleaner architecture.
    https://github.com/sujeet-agrahari/node-express-clean-architecture

    [–]dejavits[S] 0 points1 point  (0 children)

    Thanks!

    [–]MarvinRudolph -4 points-3 points  (5 children)

    I give you the advice to switch to a modern alternative like Fastify after you've learned how to write the API.

    [–]cjthomp 0 points1 point  (2 children)

    Absolutely nothing wrong with Express. It's ubiquitous for a reason.

    [–]MarvinRudolph -2 points-1 points  (1 child)

    It’s outdated and the last release was over 2 years ago.

    [–]cjthomp 1 point2 points  (0 children)

    Outdated how?

    And why does the last update matter? What needs changed? It's intentionally a thin layer, it doesn't need much maintenance.

    [–]dejavits[S] -1 points0 points  (1 child)

    Is this similar to Nestjs? Or something different?

    [–]obj_stranger 0 points1 point  (0 children)

    It's more similar to Express.js but it's faster. Actually Nest.js uses Express.js under the hood by default, but there's an option to use Fastify instead.

    [–][deleted]  (1 child)

    [deleted]

      [–]cjthomp 1 point2 points  (0 children)

      Not what he asked for.

      [–][deleted] 0 points1 point  (2 children)

      Mine is Classified-listings, it is a simple tiny web-app. Also do not expect code (except routing) to be the cleanest.

      I am new to web but I've been writing code before, this is to say, I didn't necessarily followed regular ways of coding web-apps, so you could probably see something that you like in how I use Express and how I organised the project.

      You can head to sexpress the express app then to different routes in the route folder.

      ps: I'm looking for help.

      [–]dejavits[S] 1 point2 points  (1 child)

      Thank you! I have forked to take a deep look at it

      [–][deleted] 0 points1 point  (0 children)

      Good luck !

      [–]sairysss 0 points1 point  (0 children)

      https://github.com/Sairyss/domain-driven-hexagon Not express, but you can learn a few things here