Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
¿Cómo comparar un objeto con otro desde un archivo en el nodo?

Estoy tratando de comparar un objeto que recibo de un evento socket.io con un objeto que está en un archivo en mi computadora. Tengo la mayor parte configurada, puedo hacer que se guarde en el archivo cuando encuentra nuevos datos, sin embargo, los datos parecen superponerse y no estoy seguro de por qué/cómo (ver imagen)

ingrese la descripción de la imagen aquí

Intenté leer este https://dmitripavlutin.com/how-to-compare-objects-in-javascript/ para ver si era un problema con la lectura del archivo o si comparaba los dos objetos para ver qué elemento es nuevo (cuál vendría de los datos de socket.io)

 console.log(collection) const test = new Promise((resolve,reject) => { fs.access(collection, fs.F_OK, function (err) { //initial file access if (!err) { fs.readFile(collection, 'utf8', (err, data) => { // read file for data, if (err) throw err; var dat = JSON.parse(data) var found = [] for(i in dat){ found.push(JSON.stringify(dat[i])) // This is the data that already exists, this is coming from the file. } resolve(found) // resolve }) } }) }) test.then(function(data){ //console.log(data) // This is the data from above for(i in NFTCollection){ // NFTData that was just recieved from the https request (sent from socket.io) var item = JSON.stringify(NFTCollection[i]) // This is each new item var target = client.channels.cache //console.log(data) if(!data.includes(item)){ // This is where i have the issue, how do i compare the object to the object thats in the file? console.log("Found item! " + item) var parsedItem = JSON.parse(item) data.push(JSON.parse(item)) } //console.log(item) } fs.writeFileSync(collection,JSON.stringify(data)) // saves the data from, but it keeps overlapping? }) }) })

Comenté en mi código lo que cada paso está tratando de lograr, el problema está al final. cuando comparo si los elementos de los datos de socket.io existen dentro de los datos que son el archivo node.fs.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!