Can't connect to NeDB on render process Electron

我的未来我决定 提交于 2021-01-29 19:52:07

问题


I have problem with connect NeDB to my react-electron app. Now I install NeDB on my project and connect him to electron.js file.

const Datastore = require('nedb');
let db = {};
db.students = new Datastore({
    filename:'./students.json',
    autoload: true
})
db.students.insert({name : "Putin V.V.", year: 1952});

Now I need connect this db to my app.js file. How I can manipulate with this file on render part?

GitHub code


回答1:


You can achive your idea by using ipc at Electron. I posted an answer before. Please check the below.

how to communicate between react and electron

But here is the pre-requirements.

You should enable the nodeintegration when you are creating the BrowserWindow So at your code, it should be like this

mainWindow = new BrowserWindow({
        width: 1280,
        height: 720,
        minWidth: 900,
        minHeight: 600,
        show: false,
        icon: "",
        webPreferences: {
            nodeIntegration: true
        }
    });

After this, you can use this ipcRenderer at renderer(your react app). If you don't set this option. Then you will face the similar issue as below

ipcRenderer not receiving message from main process



来源:https://stackoverflow.com/questions/60482559/cant-connect-to-nedb-on-render-process-electron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!