Reputation: 85
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
Upvotes: 0
Views: 515
Reputation: 5
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
Upvotes: 0
Reputation: 615
app.use(express.urlencoded({ extended: false }));
Try to add this to your middlewares. After express.json()
Upvotes: 1