Software | Link |
---|---|
Git | download and install |
Node.js/npm | download and install |
Docker | download and install |
Docker Hub | create an account |
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
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.
Already in use
error, please stop processes that are using the indicated ports.
Discover the app API using this Postman Collection:
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 🔍
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.
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/.
Logs are stored into the volume
, so that they can be preserved between application restarts.
- Open the Docker Desktop app.
- Navigate to the
Volumes
tab. - 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
).
- Go to
main.ts
file. - 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');
});
- Uncomment it and save the file.
- Wait until the container is rebuilt
- Check the log files according to the aforementioned instructions.
💡 Tip: You can also observe how the Logger works when you run tests!
To run all tests without authorization:
npm run test
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.
npm run test
command should be run using npm run test:refresh
instead.
🔗 Once the app is running, you can easily access the OpenAPI documentation by typing http://localhost:4000/doc/ into your browser's address bar.
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
Press F5 to debug.
🔗 For more information, please check this link.