I am trying to test my project out, and I am using postman right now to pass in some data: I have set postman to "POST" to my local server through "body", and then I send the following:
{
"name": "My Name"
}
Then, my server file post request is:
const express = require('express'),
router = express.Router(),
gravatar = require('gravatar'),
bcrypt = require('bcryptjs'),
{check, validationResult} = require('express-validator');
// User Model
const User = require('../../models/User');
// @route GET api/users
// @description Test Route
// @access Public
router.get('/', (req, res) => {
res.send("User Route")
});
// @route POST api/users
// @description Register User
// @access Public
router.post('/', [
check('name', 'Name is required').not().isEmpty(),
check('email', 'Please enter a valid email address').isEmail(),
check('password', 'Password must contain at least 6 characters').isLength({min: 6})
], async (req, res) => {
return res.send(req.body);
});
module.exports = router;
I put in the res.send(req.body) to confirm anything is being sent to my server in general before I test any of the other code out, however, the res.send only returns: {} meaning that no json information has been sent to my server. I know that the routes work because when I put in a GET request, it acts as expected. Is there something obvious I am missing here? Thank you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.