Building the Back-End

Aaditya Naik
MusicManaged Development Blogs
2 min readApr 2, 2019

As we mentioned in one of our previous Developer Blogs, we had discussed on the framework to use for the back-end. The choices seemed limitless- there were different languages- Python, JS, PHP to name a few- and the numerous frameworks built on each. After some consideration, which mainly involved the ease of programming, we settled on NodeJS and decided to use ExpressJS to render the static HTML documents and also set up the servers and ports.

We also had to settle on a suitable database manager. While an SQL based database could be used, we had to take into account that we had to store files as well as user information associated with the files, on top of being able to stream the files to the client. We looked into the possibility of using MySQL for this but later decided to opt for MongoDB. It was simply a better system to handle files.

Our goal with Music Managed was not just to create a website where people could store and retrieve their music files from, but also a service which others could use to connect with our database and make other clients to our common backend. We therefore set up routes for a RESTful API- one which could theoretically be called by any device to perform the basic functions and gain access to the basic features of the Music Managed site. Our backend is thus comprised of two parts- one for the API and one for the website.

Let us take a look at the API first- all the API endpoints are preceded by a ‘/api/’ string, which indicates the routes for the API as opposed to the routes for the website itself. The endpoints allow for adding a user, checking entered credentials, adding music, removing music, getting tags for the music file and more.

The website backend on the other hand is merely responsible for rendering the pages using Express JS templates and making them dynamic and responsive. The backend does not interact with the database on its own- it in fact calls the API which in turn handles the database processing and returns a response based on the success or failure of the function.

The backend is a complex structure and has to make use of many npm packages to be able to function properly. Most notable is the use of the mongo package which allows for seamless interaction with the mongodb database- all of the database interactions work with this package to establish connections and write to and read from the database. Apart from the mongo package helps in communicating with the database, Music Managed uses bcrypt- a package which generates a hash of a string and can verify a string with a hashed version- for hashing passwords and validating them and node-id3- a package which allows nodejs applications to read and write tags to an mp3 file. These tags allow for the user to customize the mp3 files by changing the title, year, album, artist and cover art of the mp3 file, which is then reflected in the library.

--

--