Nodejs and NPM: You can install the latest version here docker: Install docker engine from here. docker-compose: installation from here
First install dependencies:
npm install
And then start the project:
Put these variables in a .env
file at the root of the project:
DATABASE_URL=mongodb://user:password@127.0.0.1:27017/database
PIXABAY_API_KEY=YOUR_KEY
TEST_ARGON_HASH=$argon2id$v=19$m=65536,t=3,p=4$bG9uZ2VyX3NlY3JldA$7ImNgJ6BLAKruqwzKN5lYX0hb4+aXW7NN9LSSAQ98ko
HASH_SALT=longer_secret
HASH_SECRET=longer_secret
REDIS_PASSWORD=password123
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=password123
PORT=3001
Change PIXABAY_API_KEY
to your own key.
npm run start:dev
It also automatically creates a private and public key in the root of the project so you can use authentication using jwt.
Now the service is up and is listening on: http://127.0.0.1:3001
We are using Jest as both test library and test runner. For running ts test files we are using SWC which is a lot faster than TS-NODE.
npm run test
npm run test:watch
npm run test:ci
Do the development step before running the tests. There is before script that runs docker-compose file and the tests have access to the database.
Test coverage badge is updated with each push
run:
npm install
and then
npm run deploy
This is just for testing, the hash secret and passwords should be replaced with k8s secrets in case of production usage
It runs all the needed containers including the node application on port 3000.
You have to have PIXABAY_API_KEY
, and as a env variable or directly set it into the deploy.yml file.
For Linting we are using ESLint
npm run lint
For Formatting we are using Prettier.
npm run prettier
It is forced to commit Conventional Commit to this repository. For commiting in this style you can use this VSCode Extension or use this CLI Tool that I implemented.
For formatting and linting before commit and also testing commit message standard.
We are using Zod for validation of requests.
As a nosql database it was a good choice in here, even if we have millions of users with a lot of favorite contents there should be no problem.
I have used it for caching the requests that we are sending to Pixaboy, Pixaboy data is updated only once in a 24h, I am also caching the result so we do not need to pay for anything if we have are sending the same request.
Quite Standard library, very mature without security issues.
We are using winston for adding logs to the project.
Pipeline has these steps:
On this one I am building the application docker and push it to docker registry and we can use this image in docker or k8s
We have a modular monolith, each module consist of a route.ts
, service.ts
and a model.ts
for separating the concerns.
We have integration tests for everything. For some uses cases there are also unit tests for small functions.
We have login and register inside users module. but some functions which are purely related to authentication are moved to authentication module.