Search This Blog

Monday, August 21, 2017

NodeJs Access Form-Data Property Values

For recent version of NodeJs, You have to install multer plugin.

Package.json

{
  "name": "form-data-nodejs",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "body-parser": "~1.15.1",
    "cookie-parser": "~1.4.3",
    "express": "~4.13.4",
    "multer": "^1.3.0"
  }
}

app.js

const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

//let multer = require('multer');
//let upload = multer();
//if let gives error, use var

var multer = require('multer');


var upload = multer();

app.post('/send', upload.fields([]), (req, res) => {
  let formData = req.body;
  console.log('form data', formData.test);
  res.sendStatus(200);
});


>> node install --save
>> node app.js




https://github.com/expressjs/multer




Post a Comment

Hit Counter


View My Stats