Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use JsonDB while exported #351

Open
rockysoft8 opened this issue Jan 28, 2022 · 0 comments
Open

Unable to use JsonDB while exported #351

rockysoft8 opened this issue Jan 28, 2022 · 0 comments

Comments

@rockysoft8
Copy link

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')
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant