K
K
killreals2022-03-03 11:49:22
JavaScript
killreals, 2022-03-03 11:49:22

How to send and receive data in node.js server?

I am new to node.js , there is a code like this in vile api

var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
     res.send('API is working properly');
     });
module.exports = router;

I want to send a request to the server from the client, pass an object, for example. What do I need to add to send this date to the server, and there to catch and display this object, for example? I have so far written such a simple request that returns me 'API is working properly', but I tried to push the date into the body, but nothing happenedconst data = { username: 'example' };
function datasend(){
  fetch(`http://localhost:9000/testAPI`)
 
  .then(function (data) {  
    console.log('Request succeeded with JSON response', data);  
  })  
  .catch(function (error) {  
    console.log('Request failed', error);  
  });
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-03
@Seasle

https://expressjs.com/en/resources/middleware/body...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question