Giter Site home page Giter Site logo

cornercleanarchitecturenode's Introduction

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

cornercleanarchitecturenode's People

Contributors

siro47 avatar siroramirez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cornercleanarchitecturenode's Issues

Asking for suggestion

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.

Detected: Promise anti pattern

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:

  • /db/groups.js:
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);
            })
    })
}
  • /domain/groups.js:
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):

  • /db/groups.js:
exports.getGroup = function (groupId) {
    return Group.findOne({_id: groupId});
}
  • /domain/groups.js:
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! 😊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.