https://github.com/jangbl/node-dependency-injection
Express app that uses awilix for dependency injection
https://github.com/jangbl/node-dependency-injection
awilix awilix-express dependency-injection dependency-injection-container dependency-injection-framework inversion inversion-of-control-container node node-dependency-injection
Last synced: about 2 months ago
JSON representation
Express app that uses awilix for dependency injection
- Host: GitHub
- URL: https://github.com/jangbl/node-dependency-injection
- Owner: jangbl
- Created: 2020-05-21T19:57:50.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-13T11:04:48.000Z (about 2 years ago)
- Last Synced: 2024-10-03T21:37:57.847Z (9 months ago)
- Topics: awilix, awilix-express, dependency-injection, dependency-injection-container, dependency-injection-framework, inversion, inversion-of-control-container, node, node-dependency-injection
- Language: JavaScript
- Size: 892 KB
- Stars: 43
- Watchers: 1
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dependency Injection in Node with awilix
This repository contains sample code on how to do dependency injection with the [awilix](https://github.com/jeffijoe/awilix) framework.
Please help this repo with a ⭐️ if you find it useful! 😁
This repository is part of the [Dependency Injection in Node](https://www.youtube.com/playlist?list=PL1Nml43UBm6ez_JKgCUpgkwfh9oQLjVmm) tutorial series provided by [productioncoder.com](https://productioncoder.com/).
[](https://www.youtube.com/playlist?list=PL1Nml43UBm6ez_JKgCUpgkwfh9oQLjVmm)
For updates, please reach out to [@_jgoebel](https://twitter.com/_jgoebel) on Twitter.
# How to run this application
## Running the project
### Install dependencies
Make sure to install the dependencies with `npm`
```
npm install
```### Running a local Postgres instance
Make sure that you have a local Postgres instance running and that you execute the `SQL` statment in the `migrations` directory.
After you have created the tables, make sure that you update the `config/index.js` file with your Postgres configuration (hostname, port, password, etc)
### Starting up the local server
You can then run the project by executing
```
npm run dev
```## API
### POST /dev
Expected payload
```
{
"email": "[email protected]",
"firstName": "John",
"middleNames": "Alexander Tom",
"lastName": "Smith"
}
```The server will return a `400` bad request error if the request body does not conform to the expected DTO (data transfer object).
This endpoint will normalize the `firstName` field by truncating the whitespace and by moving all names after the first space to the middle names field.
Please check out the `./dto` directory to learn more about the expected request body.
### GET /dev/:id
`GET /dev/:id` returns a developer associated with the specified `id`.
Response format:```
{
"email": "[email protected]",
"firstName": "John",
"middleNames": "Alexander Tom",
"lastName": "Smith"
}
```