DEV Community

Cover image for The perfect architecture flow for your next Node.js project

The perfect architecture flow for your next Node.js project

Brian Neville-O'Neill on October 15, 2019

Written by Piero Borrelli✏️ A good start is half the battle, said someone wiser than me. And I can’t think of any quote that would better describe...
Collapse
 
pixelscommander profile image
Denis Radin

"Use promises" is a bit 2015 kind of advice. Async / await is widely adopted and it is a step ahead of Promises.

Collapse
 
wilomgfx profile image
William Cantin • Edited

That's like saying you won't be using promises with async/await.

It's just a different way of consuming them.

Collapse
 
brumor profile image
Paul Bricout

Exactly, I use promises exactly to get my async function to await for a second function to finish. They are different things

Collapse
 
chrischenyc profile image
Chris Chen

+1 for Rule #8: Use another layer for third-party services calls

I worked at 3 startups all involved with online payment, all switched from one payment processor (Stripe, Adyen, and whatnot) to another for a better rate or more features, mostly for a better rate. After going through the painful refactoring for the first 2, I realised I should've written a wrapper around whatever payment processor npm/API I would use

Collapse
 
dandv profile image
Dan Dascalescu

Yes but you have to create a unified API. Thankfully this should be easier for payment processors than for writing a unified DB access layer that would allow switching from MySQL to MongoDB.

Collapse
 
lineldcosta profile image
lineldcosta

Hey Brian,

Thanks for the great article. Any sample repo's to checkout?

Thanks,
Lionel

Collapse
 
fauzanss profile image
Akhmad Fauzan
Collapse
 
xinglong717 profile image
xinglong717

i'm interesting for this deal.

Collapse
 
dandv profile image
Dan Dascalescu

What do you mean?

Collapse
 
romainlanz profile image
Romain Lanz • Edited

Good writing, but I'd not use express for any kind of project.

If you want a real stack use something like Adonis or Nest which have been built to create application/api at scale.

Collapse
 
lexiebkm profile image
Alexander B.K.

By default, NestJs uses Express under the hood, so at least having good knowledge in Express, for me, may help in understanding and using NestJs for large scale apps.
As for AdonisJs, it looks very promising, since it is similar to Laravel for PHP. Having used Laravel in my last project, I think I can get started relatively quickly with AdonisJs. I just want to be convinced that this framework is really reliable, because I don't know, I always feel hesitant about it.

Collapse
 
erasmuswill profile image
Wilhelm Erasmus

Rule #6 has some buggy code. database is specified for the arrow function param but db is being called

Collapse
 
orimdominic profile image
Orim Dominic Adah

You noticed too? Well, we all get the gist tho 😉

Collapse
 
raulingg profile image
Raul Robinson Quispe Mendez

Do you have some project as boilerplate where I can follow these valuable rules?

If yes,do you mind to share it?

Thanks for your post!

Collapse
 
leandroandrade profile image
Leandro Andrade

Congrats.

I'd like to point of Rule #13.

The problem when use compression library you may have lot of CPU usage. The good approach for this use case is using a reverse proxy, like ngnix.

Collapse
 
steeve profile image
Steeve

Your article is interesting for beginners. CLI provided by frameworks (Vuejs, Angular, express) are generating scaffolds to learn from! It's a good starting point to follow.

Collapse
 
jamesd profile image
James David

Thanks!

Collapse
 
cassiodias profile image
Cássio Dias

Wonder if you have more examples on how to execute the piece of code about DI from a caller perspective. Thanks, great post.

Collapse
 
saurabhdaware profile image
Saurabh Daware 🌻

Thank you for this post! this was very helpful 🌻

Collapse
 
holtmansfield profile image
Holt Mansfield

I'm always amazed at how under-architected most node code is.

Collapse
 
orelkan profile image
Orel Kanditan

I really liked the functional approach of the dependency injection