Simple CQRS/ES Node+Express+TypeScript REST API

Simple CQRS/ES Node+Express+TypeScript REST API

BabyFoot Simple CQRS/ES Node+Express+TypeScript REST API

BabyFoot

Goals

  • Applying simple CQRS/ES and DDD.
  • Creating a REST API based on Node + Express + TypeScript.
  • Unit Testing with coverage > 80%
  • REST API documentation, samples & testing with PostMan + NewMan (CLI automation)
  • Exploring GitHub platform possibilites & integrations (CI/CD, NPM dependencies update Automation, etc.)

Usage

  • clone this repository somewhere on your local environment with git clone https://github.com/doppelganger9/babyfoot.git (or the SSH URL if you prefer)

  • install all dependencies with npm install

  • you can check the unit tests with npm test

  • then you can run the server API with npm start, just keep the process running and in another shell:

    • run the API tests with npm newman which will use PostMan on the CLI
    • OR : open localhost:3000
    • OR : use PostMan and import collection + environment and start manually exploring the API
    • then, CTRL+C on the npm start process to stop the local development server.

Unit Testing

npm test

Unit Testing was done by leveraging Chai, Mocha and TypeScript.

It definitely helped me:

  • see my Domain in action without a UI layer on top (manual testing);
  • find a ton of errors, and fix them! even before using the API "for real";
  • debug in vscode to go step-by-step and inspect variable contents;
  • refactor blindly once everything was covered, that's the real deal 😎!

Mutation testing

Code coverage is nice, but it only really tells you which part of your code is not yet covered.

What it does not tell you is if the current coverage is really testing or just passing over code.

Enters mutation testing! By changing parts of the tested code, it checks that related unit tests covering it should fail. If not, then the test does not really test anything, it just passes over the code.

Run npm run test:mutations and check the generated Stryker Mutator in the reports directory.

Look for surviving mutants, and test them one by one by replicating the mutation on our code and then if necessary, fix it.

Fixing means either adding meaningful assertions, or removing code that is not really useful.

PostMan collection & automated REST API testing

npm run newman

I also added a Postman collection to give you something to test the API with.

I find it great for APIs because:

  • you can play with it,
  • you can run automated tests,
  • you can provide sample calls
  • you can document your API
  • and you can export cURL shell commands (or any HTTP call code you want).

Also my goal is to automate this with Newman.

Future plans

  • Use Jest for Unit Testing? Well, as we use Stryker Mutator for mutation testing, keeping Mocha make it faster as it is able to only run tests for mutants as required; Jest runner is not yet capable of doing that.
  • have Continuous Deployment, etc.
  • add more API endpoints/features.
  • add a PWA client for the API.

Thanks

Code of Conduct

See CODE_OF_CONDUCT.md

Contributing

Well, I'm honored you are even thinking about contributing to this project 🤗

This is one of many side project, made for fun, and to explore some concepts and technology I was not using on my daily job.

I will not be actively maintaining it, just looking from afar, coldly, waiting for your contributions (issues, comments, questions, PRs..), or for my curiosity to arise again.

I do not have set up a proper CONTRIBUTING.md guide 🤭 so let's just say all contributions are welcomed 😉. You should follow our Code of Conduct 🤝. Use the GitHub platform 😎:

  • open an issue for discussion
  • create a Pull Request
  • do your best for the automated checks to pass before merging is possible

Anyway, I will review any PRs and do my best to provide answers and make merging happen, and clarify the CONTRIBUTING rules using a test & learn approach as the need arise.

You can of course message me on Twitter @doppelganger9.

Download Details:

Author: doppelganger9

Source Code: https://github.com/doppelganger9/babyfoot

nodejs node javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Node canvas is a Cairo backed Canvas implementation for NodeJS.

node-canvas is a Cairo-backed Canvas implementation for Node.js.

What Is Nodejs Used For? | Nodejs Use Cases

A decade has passed since initial release of the node.js, it has gained immense popularity. Read in this article, what is nodejs used for? Nodejs Use Cases.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer](https://hourlydeveloper.io/hire-dedicated-node-js-developer/ "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Decoding Nodejs

The main goal of this blog is to explain the “Architecture of Nodejs” and to know how the Nodejs works behind the scenes. Generally, most of the server-side languages, like PHP, ASP.NET, Ruby, and including Nodejs follows multi-threaded architecture. That means for each client-side request initiates a new thread or even a new process.