I am trying to create an api and send post request using the postman, but for some reason I'm not getting the data which is sent through the post man. Instead when I cancel the postman send request I get response which is shown in the screenshot.
nodejs server response screenshot:
server.js
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors');
// importing custom created modules
const config = require('./config');
// Instantiating express
const app = express();
// Connecting to the mongodbLab
mongoose.connect(config.database, { useNewUrlParser: true }, (error) => {
if (error) {
console.log('Error :',error);
} else {
console.log('Connected to the database.');
}
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(morgan('dev'));
app.use(cors);
const userRoutes = require('./routes/account');
app.use('/api/accounts', userRoutes);
// Running the server at port 3000
app.listen(config.port, error => {
console.log('Server started with config file at Port: ' + config.port);
});
account.js
const router = require('express').Router();
const jwt = require('jsonwebtoken'); // Encrypts user data.
router.post('/signup', (req, res, next) => {
console.log(req.body);
});
module.exports = router;
I tried even changing from https://localhost:3000 to http://localhost:3000 as suggested in this post Here
And even tried adding res.end() as suggested here and here. But nothing is working, If I goto localhost:3000 the server just keeps loading infinitely. Please help!