NodeSpring
NodeSpring is a framework to create NodeJS applications using common patterns used in other programming languages like Java and frameworks like Spring.
$ npm install nodespring
Concepts
The concepts used by NodeSpring:
-
Controllers The end points where you deal with HTTP methods (GET, POST, etc.) and invoke the service layer
-
Services Since you have several modules in your application, it's a good practice to have a service layer where you define the way that those modules are going to communicate each other
-
Interfaces An interface in NodeSpring is a Javascript class (ES6) where you define methods without business logic, just the definition.
-
Implementations An implementation is a class that implements all the methods defined on the interface, here is where your business logic should be placed
-
Unit tests They are Javascript classes (ES6) where you test every single method of your Service/Implementation using the mechanism provided by NodeSpring
How they looks like?
Controller:
@Controller @ usersService @ { return usersService } @Get { return usersService }
Service:
@Service @ dbService { return dbService } { return dbService }
Interface:
@Interface {} {}
Implementation:
// import your mongo library @ { return { // MongoDB stuff } } { return { // MongoDB stuff } }
Notice that you aren't using MongoDB directly in your service layer, instead, you have a specific implementation to deal with DB operations, if the database engine needs to be changed in the future, you only need to create a new implementation of the interface DBService.
Unit Test:
@TestClass @ dbServiceMock @ myUsersService @Before { // stuff before each test } @Test { thisdbServiceMock { // Simulating async behavior } } @Test { assert assert }
Examples
There's an example application created by using NodeSpring in this repository:
https://github.com/calbertts/nodespring-example
All of this is in progress, so it can be changed.