I am trying to learn EJS and make a blog but I cant seem to understand this error
What I am trying to do is try to write some db response as an Object to an array then push it to the file. I am using replit DB
const fs = require("fs")
const Database = require("@replit/database")
const db = new Database()
exports.load = async function(){
db.set("hello", {
"author": "Some author 1",
"title": "Blog Post 1",
"content": "First post content",
"date_posted": "Dec 17, 2021"
})
var posts = new Array()
db.list().then(keys => {
keys.forEach(key => {
posts.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">${db.get(key).date_posted}</small>
</div>
<h2><a class="article-title" href="#">${ db.get(key).title }</a></h2>
<p class="article-content">${ db.get(key).content }</p>
</div>
</article`
)
})
});
posts = posts.join()
fs.writeFileSync("public/posts.ejs", posts)
}
Error that I am getting when I run the code:
UnhandledPromiseRejectionWarning: TypeError: posts.push is not a function