PLAYLIST API (My Songs Crate)

A Playlist API that allows for the owner to create a Database of music collections. Users are able to create an account for themselves. After creating an account, users will then be able to create their own Playlist and then add songs from the database collection.


The Playlist API protects users' password via hashing and set requirements of unique emails and usernames when registering and logging in.

Tech Stack

Server: Node, Express
Database: Mongo
Tools: Postman, Heroku

Environment Variables

Running this project requires the addition to these environments on your .env file:

  • MONGODB_URI
  • JWT_SECRET

To run my project locally, you must have the following dependencies intstalled.

To install dependencies

npm init -y

npm i:

  • express
  • ejs
  • mongoose
  • dotenv
  • expressvalidator
  • morgan
  • helmet
  • bcrypt
  • jsonwebtoken

Routes

server -app.get('/) returns message ""Welcome to 'My Songs Crate' where you create your own collection of playlists!!!"

Auth Router ('/auth') creates Users and Login

User Router

  • Router.post: Creates/Registers a new user via AuthSchema; password is hashed
  • userRouter.post: User logs in with username and password. Token is sent for further access
  • userRouter.get: the endpoint; finds all of the users. User protected with tokens

Library Data/Router

  • /library - creates a new library with a unique id
  • /addSong/id - adds a song to the library database
  • .get /library - gets/calls the library database with songs listed within an array

Playlist/Router

  • user/playlist - creates a new playlist with name of playlist created by the user
  • user/playlist/addSong/id - adds a song to the playlist via id of playlist created
  • .get /playlist/id - gets the playlist via id

Schemas

User Route Schema:

  • username: type: String, required: true,
  • email: type: String, required: true,
  • birthday: type: Data, required: true,
  • age: type: Number, required: true,
  • password: type: String, required: true,
  • createdat: type: Data, Default

Library Schema (data library)

songs:
  • songTitle: type: String, required: true,
  • artist: type: Sring, required: true,
  • year: type: Number, required: true,
  • genre: type: String, required: true,
  • duration: type: Number, required: false,
  • fileType: type: String, required: true

Playlist Schema

PlayList Name: songs:
  • songTitle: type: String, required: true,
  • artist: type: Sring, required: true,
  • year: type: Number, required: true,
  • genre: type: String, required: true,
  • duration: type: Number, required: false,
  • fileType: type: String, required: true,
  • private: type: Boolean, required: false,
  • createdat: type: Data, Default

Middeware

jwtverify: gets token from Header in Postman and matches token sent.
authrouter: uses login fuction to verify user is logged in order to post/create playlist. If password/username do not match, a 400 error will be sent.

Upcoming Features

  • More Routes
  • Swagger