How to make a clean architecture for RestAPI on NodeJs

I am going to move some REST services to NodeJS. The only thing I'm worried about is the architecture of such a solution.

Is there some kind of guidance somewhere? Of course, I saw some library, such as restock. This is a good start, but not enough.

I am looking for layer separation, dependency injection, unit tests, csrf and more.

+6
source share
3 answers

Take a look here: http://nodeframework.com/

This is a list of Nodejs frameworks for various purposes. Will you display web pages? You will probably choose one of the MVC models. Just create an API? You just need one of the REST API frameworks.

Choice for logging, unit tests, documentation style, etc. does not apply to Node (although it is relatively new). There are several Unit Test frameworks, registration frameworks, documentation styles / frames, etc. This is true for Node, as well as for Java, C ++, and other popular languages. The developers of these frameworks are trying to make the use of their software “easy” - if you are not tied to several dependencies, you can swap other parts, easily integrate them, etc.

If you are looking for an all-in-one solution, I doubt you will find it. Since each one has different tastes, there are several options for each part of the solution, and you can choose the parts that work for you (and your requirements / client). What works this time may not be the best choice next time.

I would suggest looking for an example online that is close to what you are trying to do, and then follow their example or build from my demo using the same modules.

Edit:. Following the first link, there is an outdated list of frameworks from Joyent here .

Edit2: This particular part of the Joyent list may be useful to you. Perhaps this style of the Boilerplate module will help you in your search.

+3
source

You can check this post: https://solidgeargroup.com/clean-architecture-in-nodejs

If some templates for a clean architecture are discussed, such as creating an adapter layer to isolate business logic from frameworks, make the code more reusable and verifiable.

Sample code is included for connecting to the REST and GraphQL APIs. And also for unit tests and connecting mongo db

+4
source

Check this out: https://github.com/neiesc/ListOfMinimalistFrameworks#web-framework-for-nodejs

I used express and Koa, and they were both good for REST architecture.

There is also restyling and many other frameworks, making it easy to create a clean REST API.

Most of these frameworks support testing, dependency injection, and more. I would suggest trying Express.js because it is the best.

+2
source

All Articles