lowdb icon indicating copy to clipboard operation
lowdb copied to clipboard

lowdb doesn't create database

Open uniboxx opened this issue 1 year ago • 3 comments

Hi, here my code:

import { JSONFilePreset } from 'lowdb/node';

const defaultData = { posts: [] }; const db = await JSONFilePreset('db.json', defaultData);

If I run the server with this code the db.json doesn't be created. It will if I add this line.

db.write();

As I see in the instructions it should work without the last line. Any suggestion?

uniboxx avatar Sep 18 '24 18:09 uniboxx

same here :c

Z3R0GT avatar Apr 14 '25 21:04 Z3R0GT

It's not supposed to create this file until db.write() or db.update() is called, although the wording in the README is a bit misleading.

DeBoogie avatar Apr 20 '25 19:04 DeBoogie

Your issue probably is the same as mine was. I used the path data/db.json, but the folder data didn't exist. The function will create the file, but it won't create the folder.

Timmiej93 avatar Aug 13 '25 08:08 Timmiej93