Creating a file service server with nodejs fastify and minIO

Joshua Isaac
4 min readNov 22, 2020

Why create a file service server? it provides a central but independent location on your network where you can store files and share them with users across your network. This ensures that no updates destroy or change files.

What is minIO?

MinIO is a High Performance Object Storage released under Apache License v2.0. It is API compatible with Amazon S3 cloud storage service. Use MinIO to build high performance infrastructure for machine learning, analytics and application data workloads.

So let us get started setting up the easy part. Running minIO in a docker container.

To begin with, download docker: docker is an application that simplifies the process of managing application processes in containers. Containers let you run your applications in resource-isolated processes. They’re similar to virtual machines.

to do so. follow the guideline provided by this amazing digital ocean documentation:

after uccessfullt installing docker run the command below to start minIO

docker run -p 9000:9000 \
-e "MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE" \
-e "MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \
minio/minio server /data

Open minio browser using the url http://172.17.0.2:9000 and login with the provided credentials:

MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Now that that is out of the way let us start cooking!!

Let us use the gateway service project as our broiler plate for this project. Delete contents of the routes/v1 folder and also clear out the routes/index.ts file.

In case this is the first article you are reading, go through my gateway service article and clone the repository to get started.

Let us create a few useful utilities to use. In out utils folder let us create a minioClient.ts file which contains the access and secret key above. Since we will be testing this on our local machine, ensure useSSL is false. The port should be the default 9000 and url endpoint 127.0.0.1

Another utility file we need to create is the makeBucket.ts file which accepts folder name ad argument and is responsible for creating buckets in simple terms, it will create folders where we will store our uploaded files.

let us create our routes to handle singe and multiple image uploads. We will still use the schema format that we used in the gateway service. The body will accept a folder name which will be used to create buckets.

And now for our controller.

to ensure the uploaded files can be viewed in the browser, we need to add metadata to the binary file to be uploaded.

Now let us make our route accessible.

Now let us make a request with postman.

View of uploaded files in minIO

Preview of one image

Return response with urls to uploaded files.

--

--

Joshua Isaac

I am an experienced back-end software engineer adept in bringing forth expertise in design, installation, testing and maintenance of software systems.