Uploading Images to Your Node.js Backend

Andrew Richards
The Startup
Published in
6 min readJun 25, 2020

--

While learning Node you may get to the point where you want to upload photos from your client to the backend. As someone who has struggled with Rails active storage in the past, I was delighted to find that uploading images to your server with Node is easy.

Node.js!

All it takes is an npm package, ‘Multer’, and a little bit of help from another package called ‘Sharp’.

Multer is a package maintained by the same people who maintain Express. So while Express does not have this feature built in, it is simple to add it.

So let’s get started:

Step 1: Install Multer

First head to https://www.npmjs.com/package/multer

“Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files.”

Here you will find that you can install multer like so:

npm i multer

Step 2: Set Up Options For Multer

So far while using Node, you’ve most likely only sent JSON data from the client and then parsed it into a javascript object. Now we will be sending ‘form-data’, taking the file and grabbing it’s binary data and sending that to the server.

--

--