To run this project:
· Execute 'npm install' to install all needed dependencies in the project
· Set your db configuration in config.json file
This example project requires a MongoDB database running to work
To run this project:
· Execute 'npm install' to install all needed dependencies in the project
· Set your db configuration in config.json file
This example project requires a MongoDB database running to work
You're article is really great and this repository gives me some insight about Clean architecture. I recently read the Clean architecture book and I'm searching some sample projects in node.js which use the architecture then I find your awesome repo.
Based on Clean architecture, we need to define some Interface adapter to communicate the infrastructure to use case layer. Javascript doesn't have Interface, so how do you separate the interface to its implementation in Javascript? How about port and adapter, how do you deal with it?
And also how do you define the entity? I would love to hear your suggestion.
Hi there,
First of all, 🎉congratulations🎉: such a nice article you wrote, thank you both for the effort put on it and for sharing your approach! 🙂
I was reading through it meanwhile following the code, and found out that there are some parts where you are dealing with promises / promise chaining that could be simplified even more: you are following an anti pattern that is adding some unnecessary complexity to your code.
Every time you start or follow a promise chain, you tend to create and return a new Promise (new Promise(function(resolve, reject) {})
). Consider the following pieces of code:
exports.getGroup = function (groupId) {
return new Promise(function(resolve, reject) {
Group.findOne({_id: groupId})
.then(group => {
resolve(group);
})
.catch(err => {
console.log("Error retrieving groups: " + err);
reject(err);
})
})
}
exports.getGroup = function (groupId) {
return new Promise(function(resolve, reject) {
groupsDB.getGroup(groupId)
.then(group => {
resolve(group);
})
.catch(err => {
reject(err);
})
});
}
These, could be straightforward simplified to the following (and the behavior would stay the same):
exports.getGroup = function (groupId) {
return Group.findOne({_id: groupId});
}
exports.getGroup = function (groupId) {
return groupsDB.getGroup(groupId);
}
That way, you could have this unnecessary complexity removed from your source code and it would even look much cleaner! 👌
In this case, as Mongoose calls return a Promise theirselves already, there is no need from your side to create one by wrapping your functions inside new Promise(...)
statements: the promise chain already started, you could just return that promise straightforward, and do some chaining from the outside.
You will be able to find more information about this anti pattern in the following links:
I hope I was useful in here! 😊
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.