Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

req.body returns an empty object

/* 
if you are using multipart/form-data or
require a file upload from frontend you will need a multer as middleware 
for your post/patch requests, 
otherwise you can set your frontend to send application/json 
*/
 <form action="/" method="POST"enctype="application/json">

 
Comment

why is my req.body empty

Make sure your middleware is ordered properly, and if you're using Postman 
setting the "Content-Type" header to "application/json" might help.
Comment

getting empty req.body

If testing the API using POSTMAN, ensure that 'Content-Length' header is active and set to <calculated when request is sent>.
Comment

req.body empty on posts

// Envirnoment variable
require('dotenv').config()
const express       = require('express')
const port          = process.env.PORT
const app           = express()
const cookieParser = require('cookie-parser')
app.use(express.json())
app.use(cookieParser())
router.post('/profile', (req, res) => {
  console.log(req.body);
});
app.listen(port, () => console.log(`Server listening on ${port}`))
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript count character in string 
Javascript :: binary tree implementation javascript 
Javascript :: base href angular 
Javascript :: js new array from new set 
Javascript :: grayscale image in canvas 
Javascript :: javascript auto scroll on bottom 
Javascript :: debouncing 
Javascript :: check which is dubicate in object of array 
Javascript :: insert element in specific index javascript 
Javascript :: Uncaught (in promise) ReferenceError: React is not defined 
Javascript :: jquery cget lineheight in pixels 
Javascript :: render XML in node 
Javascript :: javascript arrow function 
Javascript :: array.reverse 
Javascript :: callback hell javascript 
Javascript :: js indexof second occurrence 
Javascript :: react testing for links 
Javascript :: how to check request method was a get 
Javascript :: react conditional array item 
Javascript :: useref() in react 
Javascript :: javascripti remove int character from string 
Javascript :: sweetalert allow html 
Javascript :: regex e-mail 
Javascript :: antiforgerytoken mvc with ajax 
Javascript :: regex for a, e, i , o , u 
Javascript :: send mail in node js without password 
Javascript :: bcrypt nodejs hash password 
Javascript :: how to get day, month and year javascript 
Javascript :: access variable from another function javascript 
Javascript :: navigation react pass props 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =