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

99
Views
Matriz vacía incluso si se reciben los datos

Estoy tratando de aprender a leer de las bases de datos y ver si puedo poner todo en un archivo, sin embargo, me encontré con un obstáculo.

 const fs = require("fs") const beautify = require("beautify") exports.load = function(db) { db.set("hello", { "author": "Some author 1", "title": "Blog Post 1", "content": "First post content", "date_posted": "Dec 17, 2021" }) let postsArray = new Array(); db.list().then(keys => { keys.forEach(async key => { await db.get(key).then(value => { console.log(value) postsArray.push(`<article class="media content-section"> <div class="media-body"> <div class="article-metadata"> <a class="mr-2" href="/p">Anonymous</a> <small class="text-muted">${ value.date_posted }</small> </div> <h2><a class="article-title" href="#">${ value.title }</a></h2> <p class="article-content">${ value.content }</p> </div> </article>` ) }) }) }) const posts = postsArray.join() console.log(posts) fs.writeFileSync("public/posts.ejs", posts) }

Estoy tratando de obtener el objeto JSON como se muestra en la función db.set. Pero cuando registro la matriz final, está vacía. Aunque puedo ver que el objeto se imprime en la consola. Soy nuevo en promesas y cómo se maneja. Cualquier ayuda es apreciada.

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!