Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quiddlee/nodejs-home-library-service
๐ก Node.js Home Library Service
https://github.com/quiddlee/nodejs-home-library-service
docker jwt nestjs nodejs openapi postgresql prisma rest-api rs-school supertest swagger typescript
Last synced: 4 days ago
JSON representation
๐ก Node.js Home Library Service
- Host: GitHub
- URL: https://github.com/quiddlee/nodejs-home-library-service
- Owner: Quiddlee
- Created: 2024-03-05T10:12:58.000Z (9 months ago)
- Default Branch: sprint-3/logging-error-authentication-authorization
- Last Pushed: 2024-04-01T16:04:27.000Z (8 months ago)
- Last Synced: 2024-11-13T01:52:10.734Z (4 days ago)
- Topics: docker, jwt, nestjs, nodejs, openapi, postgresql, prisma, rest-api, rs-school, supertest, swagger, typescript
- Language: TypeScript
- Homepage:
- Size: 607 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ก๐ Home Library Service
*๐ฆฅ RS-School task.*
# ๐ Getting Started
To run the project locally, you would have to download zip file with the repository or clone it to your computer. โจ## โ ๏ธ Setup and Running
๐ค What things do you need to do in order to run our project locally?
* โก Use node 20 LTS
* โ๏ธ Installed [.git](https://git-scm.com/) on your computer.
* ๐ Code Editor of your choice.
* ๐ณ Docker.## ๐ฎ Installation And Preparation
First make sure you have all the things listed in the previous section. Then clone our repository to your computer: ๐
```
git clone https://github.com/Quiddlee/nodejs2024Q1-service.git
```or download zip file manually with the repository.
๐ฆ Navigate into project folder and run:
```
npm install
```Create ```.env``` file in the root of the project and add all the necessary variables ๐ฅ.
You can find ```.env.example``` as an example file in the project root or follow the lines below ๐บ:
```dotenv
PORT=4000CRYPT_SALT=10
JWT_SECRET_KEY=secret123123
JWT_SECRET_REFRESH_KEY=secret123123
TOKEN_EXPIRE_TIME=1h
TOKEN_REFRESH_EXPIRE_TIME=24hPOSTGRES_USER=myuser
POSTGRES_PASSWORD=mypassword
POSTGRES_DB=home-library
POSTGRES_PORT=5432
DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public"
```๐คฉ Finally run a development server:
```
docker compose up
```
Aaaaand you're done! ๐๐ฅณAfter starting the app on port from ```.env``` you can open
in your browser ```OpenAPI``` documentation by typing http://localhost:4000/doc.
For more information about OpenAPI/Swagger please visit https://swagger.io. ๐## ๐ฅ Available Scripts
๐ฆ Here you can find all the scripts that are available in the project.
โ Start the app in `base` mode:
```
npm run start
```Start the app in `dev` mode:
```
npm run start:dev
```Start the app in `prod` mode:
```
npm run start:prod
```Start the app in `debug` mode:
```
npm run start:debug
```Lint adn fix the app errors with `eslint`:
```
npm run lint
```Format the App with `Prettier`:
```
npm run format
```Type check the App with `TypeScript`:
```
npm run type-check
```## ๐งช Testing
After application running open new terminal and enter:
To run all tests without authorization
```
npm run test
```To run only one of all test suites
```
npm run test --
```To run all test with authorization
```
npm run test:auth
```To run only specific test suite with authorization
```
npm run test:auth --
```## ๐ณ Docker
Run application
```
docker compose up
```
Run application in watch mode
```
docker compose watch
```
Scan docker images for vulnerabilities
```
npm run docker:scan
```# โ๏ธ Technology Stack
## ๐ฆ Developing
* ๐ฆ **Nest.js** - The Backend Framework
* ๐ **TypeScript** - The Language
* ๐ฆ **Prisma** - The ORM
* ๐ **bcrypt** - The Password Hasher
* ๐ซ **jsonwebtoken** - The JWT Token Generator
* ๐ **Nest.js/Swagger** - The OpenAPI Documentation
* ๐ณ **Docker** - The Containerization tool## ๐งน Code Quality
* ๐งช **Jest** - The Test Runner
* ๐ซ **Supertest** - The Testing Framework
* ๐ **ESLint** โ Air-bnb base - The Linter
* ๐ **Prettier** - The Code Formatter
* ๐ **EditorConfig** - The Code Style Enforcer## ๐ External Libraries
* โ๏ธ **dotenv** - The Environment Variables Library
* ๐ **cross-env** - The Environment Variables Loader# ๐ Working with the API
๐ Following the link below, you can find ```Postman``` collection that will make your life easier while working with the API! [postman collection](https://www.postman.com/bold-spaceship-739379/workspace/node-js-service/overview)![img.png](public/img.png)
## ๐ API endpoints
The API has the following endpoints:### ๐โโ๏ธ /user
| Method | Endpoint | Description |
|--------|:----------:|------------------------------------:|
| GET | /user | Get all the users from the database |
| GET | /user/:id | Get a single user by ID |
| POST | /user | Create a new user in the database |
| PUT | /user/:id | Update a user by ID |
| DELETE | /user/:id | Delete a user by ID |### ๐๏ธ /track
| Method | Endpoint | Description |
|--------|:-----------:|-------------------------------------:|
| GET | /track | Get all the tracks from the database |
| GET | /track/:id | Get a single track by ID |
| POST | /track | Create a new track in the database |
| PUT | /track/:id | Update a track by ID |
| DELETE | /track/:id | Delete a track by ID |### ๐ฝ /album
| Method | Endpoint | Description |
|--------|:-----------:|-------------------------------------:|
| GET | /album | Get all the albums from the database |
| GET | /album/:id | Get a single album by ID |
| POST | /album | Create a new album in the database |
| PUT | /album/:id | Update a album by ID |
| DELETE | /album/:id | Delete a album by ID |### ๐ฉโ๐ค /artist
| Method | Endpoint | Description |
|--------|:------------:|--------------------------------------:|
| GET | /artist | Get all the artists from the database |
| GET | /artist/:id | Get a single artist by ID |
| POST | /artist | Create a new artist in the database |
| PUT | /artist/:id | Update a artist by ID |
| DELETE | /artist/:id | Delete a artist by ID |### ๐ /favs
| Method | Endpoint | Description |
|--------|:-----------------:|---------------------------------------------:|
| GET | /favs | Get all the favorites from the database |
| GET | /favs/track/:id | Get a single track from favorites by ID |
| GET | /favs/album/:id | Get a single album from favorites by ID |
| GET | /favs/artist/:id | Get a single artist from favorites by ID |
| POST | /favs/track/:id | Add new track to favorites in the database |
| POST | /favs/album/:id | Add new album to favorites in the database |
| POST | /favs/artist/:id | Add new artist to favorites in the database |
| DELETE | /favs/track/:id | Delete a track by ID from favorites |
| DELETE | /favs/album/:id | Delete a album by ID from favorites |
| DELETE | /favs/artist/:id | Delete a artist by ID from favorites |## ๐ Response examples
**GET /users**
```json
[
{
"id": "62a13ccf-6de5-46ae-81dd-81a81301071d",
"login": "loeegin",
"version": 1,
"createdAt": 1710072081506,
"updatedAt": 1710072081506
},
{
"id": "2d2f65be-73af-40d2-842e-4514fc86c664",
"login": "loeegin",
"version": 2,
"createdAt": 1710072083360,
"updatedAt": 1710072913111
},
{
"id": "9fcd76d7-4d5b-45a0-9937-0b7cc9007e52",
"login": "loeegin",
"version": 1,
"createdAt": 1710072084156,
"updatedAt": 1710072084156
},
{
"id": "0d411947-0d1d-495d-aa64-04fe4a9e0549",
"login": "loeegin",
"version": 1,
"createdAt": 1710072084910,
"updatedAt": 1710072084910
}
]
```**GET /users/:id Error case**
```json
{
"message": "User not found!",
"error": "Not Found",
"statusCode": 404
}
```