Skip to content

haslie22/nodejs2024Q1-service

Repository files navigation

📚 Home Library Service

📋 Prerequisites

Software Link
Git download and install
Node.js/npm download and install
Docker download and install
Docker Hub create an account

🛠️ Installation and Set Up

1️⃣ Clone this repo:

git clone https://github.com/haslie22/nodejs2024Q1-service.git

2️⃣ Install NPM modules:

npm install

3️⃣ Rename .env.example file to .env:

cp .env.example .env

🚀 Running the Application

Run the multi-container application:

npm run docker:start

Application starts on the port indicated in the .env file or default (4000) port.

Postgres database starts on the indicated in the .env file (5432) port.

⚠️ If you encounter Already in use error, please stop processes that are using the indicated ports.

📙 Postman Collection

Discover the app API using this Postman Collection:

Run In Postman

1️⃣ Follow the link by clicking the orange button
2️⃣ Press Fork Collection button in the popup
3️⃣ Fill in Fork label and Workspace fields, or leave them as-is
4️⃣ Proceed by clicking the Fork Collection button
5️⃣ Set the neccessary values for the environmental variables in the Variables tab
6️⃣ Send requests and explore the responses 🔍

📦 Docker Features

To perform a vulnerability scan and receive recommendations from Docker Scout, execute the following command:

npm run docker:full-analysis

🔗 To view the repository containing the app image on Docker Hub, please visit this link.

🗃️ Prisma Features

To access the GUI of the database, you can initiate it by running the following command:

npx prisma studio

🔗 After executing the command, you can open the GUI in your browser by typing http://localhost:5555/.

🚦 Logger and Exception Filter features

Logs are stored into the volume, so that they can be preserved between application restarts.

To view the log files:

  1. Open the Docker Desktop app.
  2. Navigate to the Volumes tab.
  3. Click on the nodejs2024q1-service_logs volume.

The logs are separated into different files according to their level. The name of the file consists of the log level and counter (e.g. log-1.log, error-3.log, warn-2.log).

To test Logger and Exception Filter:

  1. Go to main.ts file.
  2. Find the following piece of code:
await app.listen(APP_PORT, () => {
  loggingService.log(`Application started on port ${APP_PORT}`);

  // Uncomment the next lines to test Logger and unhandled exceptions/rejections.
  // Get acquainted with README to get more info about logs.

  // loggingService.error('Test Error');
  // loggingService.warn('Test Warn');
  // loggingService.log('Test Log');
  // loggingService.verbose('Test Verbose');
  // loggingService.debug('Test Debug');

  // Promise.reject('Test UnhandledRejection');
  // throw new Error('Test UncaughtException');
});
  1. Uncomment it and save the file.
  2. Wait until the container is rebuilt
  3. Check the log files according to the aforementioned instructions.

💡 Tip: You can also observe how the Logger works when you run tests!

🧪 Testing

Parts 1-2

To run all tests without authorization:

npm run test

Part 3

To check authorization:

npm run test:auth

To check refresh token functionality:

npm run test:refresh

❗ If the tests fail with a read ECONNRESET error, it means that the container is currently rebuilding and unavailable. Please wait a moment and try again.

⚠️ After adding the authentication functionality, tests which previously could be run with npm run test command should be run using npm run test:refresh instead.

📝 Documentation

🔗 Once the app is running, you can easily access the OpenAPI documentation by typing http://localhost:4000/doc/ into your browser's address bar.

🌸 Auto-fix and Format

To check existing linting and formatting:

npm run lint
npm run format

To fix linting and formatting:

npm run lint:fix
npm run format:fix

Debugging in VSCode

Press F5 to debug.

🔗 For more information, please check this link.

About

Final task of Node.js RSS course (2024Q1)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages