Coder Social home page Coder Social logo

express-example's Introduction

Express example

This example will not run! Some parts are not implemented.

This API specific Express app example is demonstrating in my opinion a good architecture.

You can also read these slides for presentation called "Good Express.js Architecture":

Note: the terminology in this exampls is a bit different than in the slides. controller = endpoint = http-layer and service = core = business logic.

Here's how the Express API application has been architectured in the example:

architecture

Good with this setup:

  • Your code can leverage Promises

  • Testable

    • Express app instance can be created with a function

    • Router instance can be created with a function

    • Core methods are testable. This would allow you to write some lower level tests.

      Note: even though they are testable, usually you get the best ROI by testing with real HTTP API calls. In other words: put your express app running locally, init db to certain state, and fire http requests to localhost with e.g. supertest lib.

  • Provides a minimal but nice "frame" around your development with separation of concerns

  • Error handling is done in one place, in the error-handling middlewares defined in app.js

  • Your request handling code can throw errors and they will be handled at the app level

    No need to repeat the next(err) pattern in all your request handlers.

express-example's People

Contributors

kimmobrunfeldt 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

Watchers

 avatar  avatar  avatar

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.