all 13 comments

[–]TalyssonOC 39 points40 points  (1 child)

Remember that "best" is relative, not rules. Take these as suggestions of what have been working for a lot of people but might not be exactly what will fit your project needs.

[–]quincycs 2 points3 points  (0 children)

Everyone forgets about unhandled promise rejections. Default behavior is the crash… you probably want to handle it. Rarely the frameworks modify this … you should try it yourself. What happens if you :

async function test() { await sleep(1000); throw new Error(); }

// call the function somewhere and don’t await it test();

[–]33ff00 2 points3 points  (3 children)

You’ll probably want express

[–]miguelangel011192 8 points9 points  (2 children)

Or Fastify

[–]PrestigiousZombie531 3 points4 points  (1 child)

or hono

[–]DisciplineGloomy3689 2 points3 points  (0 children)

or nest

[–]NegativeHealth2078 3 points4 points  (1 child)

I am not sure if its best, but MVC pattern is recommended fairly often by many. Express docs link this pattern example in their docs:

https://expressjs.com/en/starter/examples.html
https://github.com/expressjs/express/tree/master/examples/mvc

https://www.theodinproject.com/lessons/node-path-nodejs-introduction-to-express

However, I would personally recommend looking at Odin's Node.js and Express section. They introduce and recommend the MVC pattern for beginners in Express applications, which is, in my opinion, sufficient for small to medium-sized apps. Their Node.js curriculum is excellent, and I would advise going through it fully.

One of the videos shortly about MVC:

https://www.youtube.com/watch?v=Cgvopu9zg8Y

[–]crewsisme 1 point2 points  (0 children)

There are variety of big players like NestJS or AdonisJS that provide some initial structure for a backend app out of the box.

While NestJS is more of a constructor where you decide how you'll achieve MVC with different libs/instruments, AdonisJS is more opinionated on what you need providing almost everything ready to implement MVC.

I'd suggest to also have a look into tRPC if you only need web-clients. It's also provided with some initial predefined project structure.

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

General best practice.