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

176
Views
Postman Stuck on sending request

So, I try to post data from postman using raw and JSON/application type but it always stuck on sending request, and this is my code:

const express = require('express');
const router = express.Router();
const User = require('../models/user');

//Getting All
router.get('/', async (req, res) => {
    try{
        const user = await User.find();
        res.json(user);
    }
    catch(err){
        res.status(500).json({ message:err.message });
    }
});

//Getting One
router.get('/:id',(req, res) => {
    res.send(req.params.id);
});

//Creating One
router.post('/', async (req, res) => {
    const user = new User({
        name: req.body.name,
        email: req.body.email,
        phoneNumber: req.body.phoneNumber 
    });
    try{
        const newUser = await user.save();
        res.status(201).json(newUser);
    }
    catch(err){
        res.status(400).json({ message:err.message });
    }
});


//Updating One
router.patch('/',(req, res) => {

});

//Deleting One
router.delete('/:id',(req, res) => {

});


module.exports = router;

I'm stuck on postman when want to post JSON file data and I use node JS and express JS, and I use MongoDB as the database. Can you guys help me to find the error in this code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

use body-parser to solve your problem , if you don't use body-parser your body will be undefined and your code has error

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: 'true' }));
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
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!