An Express.js API that interacts with a sequelize database via CRUD requests to store and interact with user, album and song information. AWS S3 implemented to store audio and image data.
Implements Test-Driven development using Mocha and Chai.
Created for the Command Shit (formally Manchester Codes) full-stack web development boot-camp final project.
$ git clone git@github.com:PerryBaran/soundcloud-clone-api.git
$ npm i
If you have Docker installed, To set the database up, pull and run a Postgres image with:
$ docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres
You will need to create a file to store your environment variables. These credentials allow you to connect to the database. Two environments will need to be created, one for production and one for testing.
Create a .env
and a .env.test
file in the root of the repo with values that meet the requirements:
PGUSER=[server name]
PGHOST=[host e.g. localhost]
PGPASSWORD=[server password]
PGDATABASE=[database name]
PGPORT=[Postgres connection port]
PORT=[local port]
JWT_SECRETKEY=[random string of characters]
AWS_ACCESS_KEY_ID=[AWS S3 Bucket access key]
AWS_SECRET_KEY=[AWS S3 Bucket secret key]
AWS_BUCKET_NAME=[AWS S3 Bucket name]
AWS_BUCKET_REGION=[AWS S3 Bucket region]
AWS_BUCKET_URL=[AWS S3 Bucket url]
App hosted on Render at https://soundcloud-clone-api.onrender.com.
- Create Render Account if not already done so.
- Click New in the top right and then select Web Service.
- Connect Render to your github account and then search for your repository and click Connect.
- Give your service a unique Name, select a Region, select the correct Branch (usually main), select the Environment, add the Build Command (e.g. npm ci) and add a Start Command (e.g. node index.js).
- Chose a Plan and then click Create Web service.
- Click New in the top right and then select PostgreSQL (if database is running on PostgreSQL.
- Give your Database a Name.
- Chose a Region and a Plan.
- click Create Database and wait.
- On Dashboard open up your Database.
- Scroll down to Connections.
- Make note of the Hostname, Port, Database, Username and Password,
- Return to the Dashboard and open up your Web Service.
- Select Enviroment on the right hand side.
- Click Add Enviroment Variable.
- The Key should be the environment variable key as defined in your local .env. The value is the the corresponding information from the Database e.g.
KEY: DBHOST, value: [Hostname value]
. Add all fields mentioned above to the Environment Variables including any required for other service e.g. AWS information.
To run the server use:
$ npm start
To run all tests use:
$ npm test
To run Prettier use:
$ npm run prettier
? In Schema represents optional field
Method | Route | Description | Schema (JSON) |
---|---|---|---|
POST | /users/signup | Create a new user and returns a cookie containing the new users name and id | { |
POST | /users/login | Returns a cookie for containing user name and id for the matching user | { |
Get | /users | Returns all users. Optional query param "name" and "limit" to search by name or limit returned results respectively | N/A |
Get | /users/:userId | Returns user the with specified ID | N/A |
PATCH | /users/:userId | Updates user with the specified ID, requires JWT authentication | { |
DELETE | /users/:userId/:password | Deletes the user with the specified ID if the password matches, requires JWT authentication | N/A |
Method | Route | Description | Schema (FormData) |
---|---|---|---|
POST | /albums | Creates a new album, requires JWT authenticaiton to link the album to the user | { |
GET | /albums | Returns all albums. Optional query param "name" and "limit" to search by name or limit returned results respectively | N/A |
GET | /albums/:albumId | Returns album the with specified ID | N/A |
PATCH | /albums/:albumId | Updates album with the specified ID, requires JWT authentication | { |
DELETE | /albums/:albumId | Deletes the album with the specified ID, requires JWT authentication | N/A |
Method | Route | Description | Schema (FormData) |
---|---|---|---|
POST | /songs | Creates a new song, requires JWT authenticaiton | { |
GET | /songs | Returns all songs. Optional query param "name" and "limit" to search by name or limit returned results respectively | N/A |
GET | /songs/:songId | Returns song with the specified ID | N/A |
PATCH | /songs/:songId | Updates song with the specified ID, requires JWT authentication | { |
DELETE | /songs/:songId | Deletes the song with the specified ID, requires JWT authentication | N/A |
Created by Perry Baran and Nicola Giannotta.