- Git - Download & Install Git
- Node.js - Download & Install Node.js and the npm package manager
- Docker - Get Docker
- Docker Desktop - Download Docker Desktop
For Linux users follow here. Here's a simple installation guide in case you're using Arch or its derivatives
# Clone the repo
git clone https://github.com/ChocolateNao/nodejs2024Q1-service.git
# Navigate to the folder
cd ./nodejs2024Q1-service
# Switch to the development branch
git checkout feat/containerization-database-orm
# Set up the .env file
cp .env.example .env
npm install
# In case of using yarn
yarn install
# In case of using pnpm
pnpm install
Docker compose file inside a root folder reates two containers:
Name | Address | Base Image |
---|---|---|
app-container | 0.0.0.0:4000->4000/tcp | node:lts-alpine3.19 |
postgres-container | 0.0.0.0:5432->5432/tcp | postgres:alpine3.19 |
You can pull the image from the official registry
docker pull choconao/rest-music-service
To bootstrap the application with database included simply run
docker compose up -d
To stop all containers and its volumes/images associated with it (optionally) (i.e clear database, delete node_modules
) run the following command
# Stop all running containers
docker compose down
# Stop containers and delete ALL volumes
docker compose down --volumes
# Stop containers and delete ALL volumes AND ALL images
docker compose down --volumes --rmi=all
To check the size of your images
docker images
To scan the built image for vulnerabilities run the npm script
You have to be logged in into docker with docker login
command as this script uses docker scout
under the hood.
npm run scan:app
Before starting the apllication the traditional way, you have to unstall PostgreSQL locally on your machine. Then, you have to point the app to the database i.e edit .env
DATABASE_URL
variable from postgres
to localhost
. This way you will be able to also reach the database inside a container. By default it's set to reach the containder's network.
# Generate SQL migration files
npx prisma migrate dev --name run
# Run the spplication
npm start
After starting the app on port (4000 as default or the one configured in .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/.
After application running open new terminal and enter:
To run all tests without authorization
npx jest test/*.e2e.spec.ts
To run only one of all test suites
npm run test -- <path to suite>
To run all test with authorization
npm run test:auth
To run only specific test suite with authorization
npm run test:auth -- <path to suite>
npm run lint
npm run format
Press F5 to debug.
For more information, visit: https://code.visualstudio.com/docs/editor/debugging