I want to send some data or requests to my node server using the get method, and receive this data and manipulate it on the server side. I know there is some ways like using postman, but i want to send it from the web page. using post the data was successfully received. here is the code am using:
//server.js
var express = require('express');
var app = express();
app.listen(3000, () => console.log('server is running on port 3000'));
app.use(express.json({limit: '5mbs'}));
app.use(express.static('client'));
app.get('/', (req, res) => {console.log(req)});
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>chat</title>
</head>
<body>
<h1>server is sending html</h1>
<script src="index.js"></script>
</body>
</html>
index.js
const a = 5;
console.log(a);
options = {
method: "get",
headers: {"ContentType" : "application/json"},
};
fetch('/', options)
as you can see am trying to send this data in a json format but in my code there is no data to send, but using post i was able at least to recive the request and i was able to console.logit and then parse the req.body. but with get there is no req.body , and am not able to even console.log req, and i am not having any error or some thing on the console. so what is wrong here, and how can i be able to send the constant a for example?
req.body, it'sreq.query