B
B
baroman4ik2022-01-23 10:54:25
JavaScript
baroman4ik, 2022-01-23 10:54:25

How to correctly learn JSON sent from the client to the server?

I send an array of data from the client via fetch:

const json = JSON.stringify(array)
    fetch("/newarray", {
      method: "POST",
      body: json,
      contentType: "application/json"
    })

The data is sent and it is visible.
61ed097592795754581837.png
On the server, I try to receive data in this way:
const express = require("express");
app.use(express.json())
app.post('/newarray', function(req, res) {
  console.log(req.body);
})

But in the console I get an empty object instead of an array of data. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question