node-json-db
node-json-db copied to clipboard
Unable to use JsonDB while exported
Hello,
I am trying to use the JsonDB in a electron package compiled via rollup but it seems I am unable to export the JsonDB object / methods. Can someone please take a look and let me know what the issue could be?
db.js
'use strict'
import { JsonDB } from 'node-json-db';
import { Config } from 'node-json-db/dist/lib/JsonDBConfig'
const log = require('../logger/logger');
let db;
if (process.env.NODE_ENV == 'production') {
try {
db = new JsonDB(new Config(process.env.DBPATH_PROD, true, true, '/'));
} catch (error) {
log.error("Database file not found: " + error)
}
}
else {
try {
db = new JsonDB(new Config(process.env.DBPATH_DEV, true, true, '/'));
} catch (error) {
log.error("Database file not found: " + error)
}
}
exports.db = db;
controller.js
let jsonDB = require('./database/db.js')
var testData = jsonDB.db.getData('/data/test')
console.log(testData)
Error
`App threw an error during load
TypeError: Cannot read properties of undefined (reading 'getData')
`