- Project implementation summary
- Compiling and running the project
- Run load script
- Adicional information (Optional)
This project was implemented using the next tools or libraries:
- Nodejs, Typescript, HapiJs, Mongodb and Docker.
- For compile and run this project you only will need Docker and Docker compose since everything is encapsulated on a Docker image.
- The Spotify authentication is implemented using the Client Credentials Flow
- The server runs in http://127.0.0.1:8888.
- Docker Engine version
19.03.12
or similar. If you don't have it installed, you can see instructions here. - Docker Compose version
1.26.2
or similar. If you don't have it installed, you can see instructions here. - (Optional) If you want to connect to Mongo database, you could install MongoDB Compass.
- Use the variable
DATABASE_CONNECTION_URI
available onconfig/.env.dev
.
- Use the variable
- (Optional) If you want to execute project on development mode, you need to install
NodeJs v12.8.3
andNPM v6.9.0
-
Create and Spotify application here, get your clientId and clientSecret tokens and setup these in
config/.env.production
andconfig/.env.dev
. -
Install Docker Engine and Docker Compose services, then start Docker Engine.
-
Open a terminal or console and navigate to project directory.
-
Create the docker network bridge used to allows communication between both containers server and database:
docker network create -d bridge --subnet 172.0.1.0/24 --gateway 172.0.1.1 songs-net
-
Execute only database for initialite it:
docker-compose up database
-
When log finish of moving, press
Ctrl + C
on your terminal to end database execution. -
Execute database and server:
docker-compose up
-
You should see a log on your terminal that looks like the following:
Server running on http://0.0.0.0:8888
- If you don't see this log, please try executing database and server by separated (two terminal), first the database and when it's ready then the server:
docker-compose up database docker-compose up server
- If you don't see this log, please try executing database and server by separated (two terminal), first the database and when it's ready then the server:
-
docs/api.html
-
docs/postman/Patagonian Backend Challenge.postman_collection.json
-
docs/postman/Patagonian Backend Challenge.postman_environment.json
-
cURL commands
# Populate curl --location --request GET 'http://127.0.0.1:8888/api/v1/songs/populate?ids=1r4hJ1h58CWwUQe3MxPuau,2gRP1Ezbtj3qrERnd0XasU' # Get songs with pagination curl --location --request GET 'http://127.0.0.1:8888/api/v1/songs?artistName=Maluma&limit=5&offset=10' # Get a song by songId curl --location --request GET 'http://127.0.0.1:8888/api/v1/songs/0GgGvBbhKzVKeiW8JdgyTh'
These are the instruction for run script that loads into a database all the songs from a list of Artist's IDs.
- The script is executed using
/songs/populate
endpoint. - Build a list of Artist's IDs separated by comma and set in ids query param.
- Execute the endpoint
/songs/populate
. Await for response that say you how much artists and albums are will be processed. - When the endpoint response, is possible that songs continue loading in background because can be a long process (depend on amount of artists) but you can check the log in the terminal.
IMPORTANT: The next commands must be executed on root project directory.
-
Execute database and server:
docker-compose up
-
Execute only database:
docker-compose up database
-
Execute only server:
docker-compose up server
-
Execute containers forcing the build:
# Both docker-compose up --build # Only server docker-compose up --build server # Only database docker-compose up --build database
IMPORTANT: The next commands must be executed on root project directory.
-
Install NPM dependencies:
npm i
-
Execute only database service using
docker-compose
:docker-compose up database
-
On another terminal execute server on development mode:
npm run dev
-
(Optional) Execute test:
npm test