Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shihabmridha/nodejs-repository-pattern-and-ioc
🛠This is a boilerplate for Node.JS, Express.JS, and MongoDB based web application that takes advantage of repository pattern and dependency injection.
https://github.com/shihabmridha/nodejs-repository-pattern-and-ioc
dependency-injection expressjs inversifyjs ioc mongoose nodejs repository-pattern typescript
Last synced: 3 months ago
JSON representation
🛠This is a boilerplate for Node.JS, Express.JS, and MongoDB based web application that takes advantage of repository pattern and dependency injection.
- Host: GitHub
- URL: https://github.com/shihabmridha/nodejs-repository-pattern-and-ioc
- Owner: shihabmridha
- License: mit
- Created: 2020-03-28T17:33:15.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-11T12:44:55.000Z (9 months ago)
- Last Synced: 2024-05-30T02:15:31.251Z (8 months ago)
- Topics: dependency-injection, expressjs, inversifyjs, ioc, mongoose, nodejs, repository-pattern, typescript
- Language: TypeScript
- Homepage: http://anotherdev.xyz/nodejs-repository-pattern-and-ioc/
- Size: 709 KB
- Stars: 101
- Watchers: 4
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### !! Work in progress
# Repository pattern & Dependency injection using TypeScript
This starter kit tries to implement a NodeJS, ExpressJS and MongoDB powered web application using repository pattern and dependency injection. The main idea is independent of any framework or database. TypeScript is used instead of JavaScript for various reasons. Especially the support for interface, generic type support, and better IntelliSense.
# Usage
- Install required modules (`pnpm install`)
- Run (`pnpm start`)
- Go to `http://localhost:3000`. You should see a static html page.Note: Run `pnpm run start:dev` for hot-reload.
# Core Features
- Dependency injection
- Repository pattern
- CI (with code coverage) using Azure DevOps## Dependency injection using InversifyJS
[InversifyJS](http://inversify.io/) is a very useful library for dependency injection in JavaScript. It has first class support for TypeScript. It is not necessary to use interface to use dependency injection because Inversify can work with class. But, we should **"depend upon Abstractions and do not depend upon concretions"**. So we will use interfaces (abstractions). Everywhere in our application, we will only use (import) interfaces. In the `src/core/inversify.ts` file we will create a container, import necessary classes and do dependency bindings. InversifyJS requires a library named [reflect-metadata](https://www.npmjs.com/package/reflect-metadata).
## Repository pattern
Main purpose is to decoupte database from business logic. If you ever decide to change the databse then you only need to update repositories. The base repository is `src/core/repository.ts`. All other repositores should be derived from it (Ex: `user.repository.ts`).
## Continious integration
The Azure Pipeline uses `azure-pipelines.yml` configuration file. The value of `$(DB_PASSWORD), $(DB_USERNAME)` etc placeholders should be replaced by pipeline variables. It published both test and coverage result.
> This might not be the best implementation you have seen or might not follow all the principals.