skip to Main Content

enter image description here

I have the following code in my node app:

// POST route
app.post('/bb', async (req, res) => {
    try {
        // Assuming you're receiving JSON data in the request body
        const newData = await req;
        // Process the new data here
        console.log('Received new data:', newData);
        res.status(200).json({ message: 'Data received successfully' });
    } catch (err) {
        res.status(500).json({ error: err.message });
    }
});

app.listen(3000, () => console.log('Server started on port 3000'));

When I try to send it some json with Postman I get:

Cannot POST /bb%0A

What am I doing wrong?

2

Answers


  1. look here

    const express = require('express');
    const cors = require('cors');
    const fs = require('fs');
    const path = require('path');
    const app = express();
    
     const port = 5500;
    
     app.use(cors()); // enable CORS
    
     app.use(express.json());
      app.use(express.urlencoded({ extended: true }));
    
    
     app.post('/test', (req, res) =>{
      console.log(req.body);
    
      res.json('okey');
     }); 
    
    
    
    
    app.listen(port, () => console.log(`Example app listening on port 
    ${port}!`));
    
    Login or Signup to reply.
  2. I see the arrow in the last URL http://localhost:3000/bb[arrow] in the postman, so you may delete that arrow and try again.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search