Unequipped.

Constant feelings of being unequipped. Just continuously coming up short. They say love yourself, but that is only half. Self Love is only half the battle when you are at war with the world. Go to…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Creating a Node.js API to upload CSV files to MongoDB

Many applications need to upload CSV files at some point to a database. This post will guide you through how to upload CSV files to MongoDB.

MongoDB is a document-oriented NoSQL database used for high volume data storage. Instead of using tables and rows as in the traditional relational databases, MongoDB makes use of collections and documents. Documents consist of key-value pairs which are the basic unit of data in MongoDB.

We will be using Express.js for server side.

Node modules that we are going to use:

Now, we need to create a schema for the CSV data that is to be stored in MongoDB.

To connect to MongoDB we need a MongoDB cluster link that should be placed in a .env file as shown:

Now we will make index.js file to make the API routes and complete the API:

Now create an empty folder named uploads in the same directory. multer will use this folder to place uploaded files.

Now, the API part is completed you can test this API using Postman or other services.

We need to create an index.html file to provide a structure to our application.

As a last step we need to create a javascript file to fetch the API we created.

Now after you keep index.html and app.js file in the same directory you can run index.html file and use it to upload csv files to MongoDB.

Final app:

If you liked this article, please drop some claps!!

If you have any questions you can ask them anytime in the comments below!

Add a comment

Related posts:

You Are Your Own Worst Enemy

If you want to get somewhere in life, you have to stop being your worst enemy and get out of your own way. You don't have to be a puppet of your life circumstances.

This Rare but Simple Skill Will Make You Instantly More Likable

But good listeners are rare. In conversation, you’re probably more self-centered than you realize. If you’re always trying to figure out how to reply while someone else is talking, then you aren’t…

I Spent Five Years Making a Documentary About an Italian Taxidermist

In the spring of 2016 I was a primarily self-taught, fledgling documentarian with a couple of shorts under my belt, and a burning desire to learn, grow, and make more documentaries. I was also…