3

So basically I wrote a simple API where you can perform http POST and http GET on a nedb. My problem however is, that after posting an entry (customer), the entry appears in the nedb file but when I use the GET method it isn't returned.

However after restarting the API it works as expected and the expected data is returned. But why does it have to restart in order to "refresh" the data?

Get-Function:

const db = new Datastore({filename: __dirname + '/db.dat', autoload:true});
export function getAll(req: Request, res:Response, next: Next):void{
    db.find({}, (err, customers) => {
        res.send(customers);
    });
    next();
}

1 Answers1

3

In situations where you get weird errors or something strange is not working with nedb and you cannot figure out what's wrong, try to delete the .dat file and try again.
Often you accidentally modify the nedb file (e.g. with autosave of your editor) and you corrupt it.