cg14
cg14

Reputation: 379

Uploading an image to file system using Node.js

I am trying to upload an image to my server through a node.js server using express. I am in the process of writing an CRUD API but I am stuck on how to POST and save the image in a directory on my server.

//post
app.post('/public/media', function(req,res){

});

This is the barebones of my post method. I am trying to store the image in my media file. How should I go about this?

Note, I am not trying to store the image into a database. Rather, I am trying to store the image in a folder on my server and simply store the path to the image in my database.

Upvotes: 0

Views: 3751

Answers (1)

Ben Rondeau
Ben Rondeau

Reputation: 3053

Without duplicating an entire article about this issue, checkout this tutorial out. You will need to make slight adjustments to this code if using Express 4, otherwise it will work great.

Comment if you have issues below.

Upvotes: 1

Related Questions