Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
form-data in postman sending Empty body to nodejs

I know this has been asked multiple times, but I have been looking around and still can't find an answer to my problem.

const express = require("express");
require("dotenv").config({
  path: ".env",
});
const PORT = process.env.PORT || 5000;
const runDatabase = require("./config/database");
const path = require('path')

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

app.use(cors())
app.use(express.json())


app.use("/uploads", express.static(path.join(__dirname, "uploads")));

// routers
const userRouter = require("./router/usersRouter");
const categoryRouter = require("./router/categoryRouter");
const productRouter = require("./router/productRouter");

app.use("/api", userRouter);
app.use("/api", categoryRouter);
app.use("/api", productRouter);

app.listen(PORT, () => {
  runDatabase();
  console.log(`๐Ÿš€The Backend Server is up and running on port ${PORT}๐Ÿš€`);
});


Here is my code, when sending the request in JSON raw postman a response is what I need but when using a form-data it will return an empty body

about 4 years ago ยท Juan Pablo Isaza
2 answers
Answer question

0

app.use(express.urlencoded({ extended: false }));

Try to add this to your middlewares. After express.json()

about 4 years ago ยท Juan Pablo Isaza Report

0

Change app.use('/', (req, res) => { to app.get('/', (req, res) => {.
app.use is intended for middleware, not normal requests.
Read more about app.use and it's usages here: http://expressjs.com/en/4x/api.html#app.use

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!