Electron Return Value to Renderer form Main


#1

I have the below code that does a database query, it returns the rows and I see the rows in console.log. However, in the renderer process I do not get the returned rows, console.log shows ‘undefined’. Am I missing something?

Main.js

exports.accounts = function() {

    db.serialize(function() {
        db.all("select * from accounts", function(err, rows) {
            if (err) {
                console.log(err);
            } else {
                return rows;
            }
        });
    });
};

app.js (renderer)

const remote = require('electron').remote;
const main = remote.require('./main.js');
$scope.accounts = main.accounts();
console.log($scope.accounts);

#2

See this previous topic for why you should probably be accessing the database from the renderer side.