سؤال

I'm thinking to move some REST Services to NodeJS. The only thing I'm worry about is the architecture of this kind of solution.

Do it exist somewhere some guideline? Of course, I saw some library like restify. It's a good start but not enough.

I'm looking to layer's separation, dependency injection, unit tests, csrf and more.

هل كانت مفيدة؟

المحلول

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

This is a list of Nodejs frameworks for a variety of uses. Will you displaying web pages? You'll likely choose one of the MVC models. Just creating an API? You'll just need one of the REST API frameworks.

The choice for logging, unit tests, documentation style, etc. isn't specific to Node (even though it is relatively new). There are multiple Unit Test frameworks, logging frameworks, documentation styles/frameworks, etc. This is true for Node as well as Java, C++, and other popular languages. Developers of these frameworks try to make using their software "easy" - in that you're not tied into multiple dependencies, can swap out other parts, integrate it easily and so on.

If you're looking for an all-in-one solution, I doubt you'll find it. Because everyone has different tastes, there are a few options for each part of the solution, and you're able to choose the pieces that work for you (and your requirements/customer). What works this time may not be the best choice the next time.

I'd suggest looking for an example on-line that comes close to what you're trying to do, and then follow their example or build from their demo, using the same modules.

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

Edit2: This particular part of the Joyent list maybe useful to you. Perhaps that "Boilerplate" style of module will help your searching.

نصائح أخرى

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

Where some patterns for Clean Architecture are discussed, like creating an adapter layer to isolate business logic from frameworks, make code more reusable and testable..

Code examples are included for connection with REST and GraphQL APIs. And also for unit tests and mongo db connection

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

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

There's also Restify, and bunch of other frameworks that makes it easy to build a clean REST API.

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top