NodeJS API built with express & mongodb to handle songs 🎵🎵
git clone https://github.com/boyney123/songs-api.git
There are two ways to get the application running.
- Locally (outside of docker)
- Using Docker
If you would like to run this locally (outside Docker) then you need to:
- Make sure you have mongo running on your machine.
- Rename
.env-example
to.env
npm install && npm start
If you would like to populate the database run:
npm run populate-database
docker-compose up -d
This should run the API and mongo within a docker environment
If you want to populate the database run:
docker-compose exec songs-api npm run populate-database
If you want to run the tests locally you will need mongo
running on your machine.
npm test
Returns an array of data for songs. Requires limit
and page
query string parameters.
Query String values:
- limit: Number - The number of songs to return
- page: Number - The page to return
Example:
http://localhost:3000/songs?page=1&limit=2 will return 2 songs for the first page. http://localhost:3000/songs?page=2&limit=2 will return the next 2 songs on page 2 and so on...
All the mp3
files are served statically. You can download the mp3
files using the /download
API.
Returns the mp3 file.
Example: http://localhost:3000/download/Decision.mp3
All the mp3s that can be downloaded are in the public/songs
directory.
- Better formatting on the logs
- Possibly adding tests for mongoose models, but they are tested within the routes?
- Production configuration files if going into production in the future
- To get Mongo and Node working with docker-compose I had to use
wait-for-it.sh
file. (Which is recommended). Given more time I wonder if this could be replaced with something better? - Maybe cache the results rather than going to Mongo all the time? For this POC and small API its fine.
- Adding auth to Mongo