Ask coding questions

← Back to all posts
ReplDB (NodeJS) not returning keys or values
Teddy007 (1)

Fairly self explanatory based on the title, any ideas as to how to solve?

This is the code I'm using right now:

const Database = require("@replit/database")
const db = new Database()
db.set("key", "value")
if (db.get("key") == "key") {
console.log("Key found")

Answered by ruiwenge2 (1186) [earned 5 cycles]
View Answer
ruiwenge2 (1186)

db.get is a promise, so do this:

db.get("key").then(value => {
  if(value == "key"){
    console.log("Key found")