Skip to content

user-of-github/nodejs2024Q1-service

Repository files navigation

Home Library Service


1. How to run:

1.1 Preparations

Ensure that you have actual versions of tools.
My ones are listed below:

  • $ node --version
    v20.11.1
  • $docker --version
    Docker version 26.0.0, build 2ae903e
  • $ uname -a
    Linux 5.13.0-40-generic #45~20.04.1-Ubuntu

1.2 Cloning & running

  • Clone this repository:
    git clone https://github.com/user-of-github/nodejs2024Q1-service.git .
  • Switch to actual branch (for task 3 it is dev-3, see actual branch in PR. Or after course completion it should be just master):
    git checkout dev-3 // or other actual branch with most recent changes
  • Ensure that ports are free (:5432, :4000) (see them in .env)
    • Note: On Linux you can use command sudo lsof -i:5432 and sudo lsof -i:4000 to check, if ports are free
  • Run npm install
  • Ensure that there is app_logs/logs.log file and app_logs/errors.log file (towards project root) (check relevant paths of lof-files in .env file). While running program you will be able to see online content of log-files, even if app is in docker, because directory is mounted
  • Uncomment whole docker-compose, in .env make sure, that DATABASE_URL for DOCKER is used (see comments in env).
    Run docker compose up or sudo docker compose up

To run app without docker:

  • Run your postgres instance locally from params in .env or you just can:
    • Comment app service in docker-compose (so only DB will be run in container)
    • in .env make sure, that DATABASE_URL for LOCAL is used (see comments in env)
  • Run npm run start or npm run start:dev.
  • Before running, you can check, that 4000 and 5432 ports are free by using command (in Linux): sudo lsof -i:5432, sudo lsof -i:4000. And kill processes if they occupy these ports (sudo kill <PROCESS_ID>)



... waiting some time ...

1.3 Testing

  • // in separate terminal :)
  • If you haven't done before, npm install
  • For now (3rd part of this project-task, dev-3) AuthModule is already implemented, so usual tests will fail. You need to run tests:
    • npm run test:auth
    • npm run test:refresh
  • DOCKER CONTAINER WITH APP SHOULD BE ALREADY RUNNING :)

1.4 After everything:

  • After testing and using, don't forget to run sudo docker compose down (even if you already pressed ctrl+c or ctrl+z in terminal)

1.5 If you are getting some error when running compose up, like this:

Error response from daemon: driver failed programming external connectivity on endpoint db ... Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use,
then ensure that port is free. You need to stop all running containers, free up port.
You can check, which process uses this port by using: sudo lsof -i:5432. With sudo !! Because without it on my personal machine command showed nothing. And then kill this process

2. Docker Hub link to my published image:

https://hub.docker.com/repository/docker/684684684/rs-nodejs-2024q1-service

3. Technologies used:


4. Features:

  • Every entity is processed within its module
  • Database has a separate module
  • Types
  • Linting
  • Launch data stored in .env
  • Auth via passport.js and JWT-tokens (for now entities are not binded to users, as it was not in task statement and there are no tests for it; But actually it is not a problem now to make reference of favourites to user)
  • Custom logging to file and logs-rotation; Logger Module; Middleware

5. Usage:

  • Users (/user route)

    • GET /user - get all users
    • GET /user/:id - get single user by id
    • POST /user - create user (following DTO should be used)
    • PUT /user/:id - update user's password
    • DELETE /user/:id - delete user
  • Tracks (/track route)

    • GET /track - get all tracks
    • GET /track/:id - get single track by id
    • POST /track - create new track
    • PUT /track/:id - update track info
    • DELETE /track/:id - delete track
  • Artists (/artist route)

    • GET /artist - get all artists
    • GET /artist/:id - get single artist by id
    • POST /artist - create new artist
    • PUT /artist/:id - update artist info
    • DELETE /artist/:id - delete album
  • Albums (/album route)

    • GET /album - get all albums
    • GET /album/:id - get single album by id
    • POST /album - create new album
    • PUT /album/:id - update album info
    • DELETE /album/:id - delete album
  • Favorites

    • GET /favs - get all favorites
    • POST /favs/track/:id - add track to the favorites
    • DELETE /favs/track/:id - delete track from favorites
    • POST /favs/album/:id - add album to the favorites
    • DELETE /favs/album/:id - delete album from favorites
    • POST /favs/artist/:id - add artist to the favorites
    • DELETE /favs/artist/:id - delete artist from favorites
  • Auth

    • POST /auth/signup - register with body {login, password}
    • POST /auth/login - login with body {login, password}
    • POST /auth/refresh - refresh tokens with body {refreshToken}

 

Inspired by Rolling Scopes
Created by Slutski Mikita
RS NodeJS 2024Q1
© 2024