node.js - Node get posted variables via body-parser -


i'm trying retrieve posted variables in node application. i'm using postman form-data (like have in many other api testing situations) post message node application. when console.log request.body, empty object. here entire node app:

var express = require('express'); var app = express(); var bodyparser = require("body-parser");  app.use(bodyparser.urlencoded({ extended: true })); app.use(bodyparser.json());  app.post('/foo',function(request,response){     console.log(request.body); });   app.listen(3000, function(){   console.log('listening on *:3000'); }); 

after posting data, here shows in console:

listening on *:3000 {} 

here package.json:

{   "name": "api",   "version": "0.0.1",   "description": "api",   "dependencies": {     "express": "^4.12.4",     "socket.io": "^1.3.5",     "body-parser": "~1.12.0"   } } 

i think i'd continue use body parser because plan on making api json data. app loads fine no errors. missing?

after tests, found out body-parser not able parse multipart/form-data state on readme, default encoding on postman.

to parse format, can use: (from readme, again)

if it's debugging purpose, set postman send either:

x-www-form-encoded checking appropriate checkbox (see picture) check "x-www-form-encoded" checkbox

or raw mode, being careful set mime header application/json or parser ignore (see picture) check "raw" , don't forget choose "application/json" encoding


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -