Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I would put the necessary logic to be executed when onSnapshot is called.

const admin = database.collection("admin").onSnapshot(documento =>{
     const final = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
     // Code that uses final here
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading