I am new in the MERN world and I need your help. I am building a small dashboard app with charts in ReactJS. This app receiving data from the Node.js server every 5 seconds. I imagine my workflow like this:
- server is receiving data on a POST request from NodeRED,
- when the POST request is triggered I would like to take the request body and send it through io.emit to the Client component. This is what I have tried, but it is not working...
.
.
.
let variable1 = 0; <-initial value
io.on("connection", (socket) => {
console.log("Client connected");
io.emit("event1", {name: "Test", value: variable1});
socket.on("disconnect", () => {
console.log("Client disconnected!");
});
});
const postMeasurement = async (req, res, next) => {
const { value } = req.body;
variable1=value;
.
.
.
Thank you in advance for your time and help.