Electronhub.com - searching electronic component made easy

Nodejs File upload using Multer and Expressjs


Nodejs File upload using Multer and Expressjs

If you are build your backend using nodejs and want to upload file from your andoroid device. Below is the snippet using nodejs , multer and expressjs.


const  express  =  require('express')
const  app  =  express()
const  util  =  require('util')
const  port  =  3000;

var  multer  =  require('multer')
//set the storage folder for the muttler
var  storage  =  multer.diskStorage({
destination:  function (req, file, cb) {

//set the upload directory
cb(null, 'upload')
filename:  function (req, file, cb) {
//set name for the uploaded file
cb(null, file.originalname  +  '-'  +  Date.now())

var  upload  =  multer({ storage:  storage });

app.get('/', function (req, res) {

//upload function
//Uploaded file will be saved in the upload folder
app.post('/upload', upload.single('file'), function (req, res, next) {

console.log("file received "  +req.file.filename);


app.listen(port, () =>  console.log(`Example app listening on port ${port}!`))

Start your node server now you can upload file to


Use postman to test your upload file function

Postman parameter

  • Select body 'content-type ' as ' form-data'
  • Set 'key' as 'file' then select file
  • Click send button