Search code examples
javascriptnode.jsnedb

Problem extracting data from NEDB database Node.JS


I have a NEDB Datastore called users which contains one line of information. I call a fetch request to retrieve the users from the server and I can tell that the request is being processed by debugging. However, the users.find() is not working and I have no idea why. When I tried the same code with an alternate datastore, it worked fine.

Here is my Javascript code:

//Client side JS
async function extractUsers() {
  const userJ = await fetch('/getUser');
  let user = await userJ.json();
  header.innerHTML = "Welcome " + user + "!";
}


//Server Side JS
const users = new Datastore('users.db');
users.loadDatabase();

app.get('/getUser', (req, res) => {
    users.find({}, (err, data) => {
        res.json(data);
    })
});
If you have any idea why this is happening or need more information, please let me know. Thanks!


Solution

  • I simply deleted the users.db file and restarted the server, manually re-entering the data and it seemed to work.