node.js - Express is not showing any params being received from a POST request -


In the node, I'm using express.router () to get the curl request. I just want to make a "hello world" and log whatever I have received

My curl request:

  curl -F "hello_world = foobar" http : // Examplesite.com/my_endpoint   

How the node handles it:

  var express = require ('express'); Var router = express.routor (); Router.route ('/ my_endpoint') .post (function (req, res) {var data = req.body; console.log (data); // This comes back empty ... Is this "Hello_world = Fubar"? });    

Rex. There is no naturally present within an express-app, for this, you need express-body-parser middleware with it:

  install npm body-parser - Save   

After that, you can easily add it to your app:

  var Express = Expected ('Express'); Var bodyParser = is required ('body-parser'); Var app = express (); // Instantiate an Express App app Use (bodyParser.urlencoded ({extended: incorrect})); // parse app / x-www-form-urlcode app. (BodyParser.json ()); // parse application / jsn var router = app. Rotor (); Router.route ('/ my_endpoint') .post (function (req, res) {var data = req.body; console.log (data); // It comes back empty ... this is "Hello_world = Fubar"? });   

edit I also noticed how you are interfering with your express app, it's a minor mistake. You do not use the router on the express itself, but on an app you just instantify the call before expressing it. I have edited this in my example above.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -