'how to get the value of an arrow function in node.js
I want to get the value of the variable "final" to be able to send to the frontend through sockets
My code
const admin = database.collection("admin").onSnapshot(documento =>{
const final = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
return final
})
const alerts = admin()
console.log(alerts);
//sockets
io.on('connection', function (socket) {
console.log('Alguien se ha conectado con Sockets');
socket.emit('alerts', alerts);
socket.on('new-alert', function (data) {
alerts.push(data);
io.sockets.emit('alerts', alerts);
});
});
//sockets
Solution 1:[1]
Yeah my final code is
//sockets
io.on('connection', function (socket) {
console.log('Alguien se ha conectado con Sockets');
const admin = database.collection("admin").onSnapshot(documento =>{
const alerts = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
socket.emit('alerts', alerts);
socket.on('new-alert', function (data) {
alerts.push(data);
io.sockets.emit('alerts', alerts);
});
})
});
//sockets
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jonathan Rivas |
