0

Recently, I am trying to make a web page using express, and I am trying to manage login session information and bulletin board data through lowdb.

But when I try to generate and run the code that requires lowdb and controls lowdb,

There is a error with the require syntax with the err_code 'ERR_REQUIRE_ESM'.

When I googled it, it said that it was a syntax compatibility problem between commonjs and ESM, so do I have to convert all other codes to ESM because of one lowdb?

The code below is the code I made to control lowdb.

var low = require('lowdb');
var FileSync = require('lowdb/adapters/FileSync');
var adapter = new FileSync('db.json');
var db = low(adapter);
db.defaults({users:[], topics:[]}).write();
module.exports = db;

I don't want to convert the whole code to ESM because of lowdb, I want to use lowdb through commonjs. Or is there any other good way to handle local db via json file like lowdb?

1 Answers1

1

Use lowdb@1.0.0 and it will work.

npm i lowdb@1.0.0

Frank
  • 317
  • 2
  • 11