X
X
xster2017-11-17 13:36:11
JavaScript
xster, 2017-11-17 13:36:11

Accept json on client from nodejs/express server?

Good afternoon! Please tell me how can I send data from the nodejs / express server and receive it in json format on the client?
There should be something like this on the server

app.get ('/', function (req, res) {
// res.setHeader ( 'Content-Type "," application / json');
res.json ({message: `API Initialized!`});
});

how to accept it on the client?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2017-11-17
@davidnum95

fetch('/')
  .then(response => response.json())
  .then(console.log);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question