Learning how to develop modules I'm trying to learn how to export one from main.js. On my renderer I can send it correctly to main with:
renderer.js:
let _object = {
foo: foo1,
bar: bar1,
}
ipcRenderer.send('channel', _object)
in main.js I can get this correctly:
ipcMain.on('channel', (e, res) => {
console.log(JSON.stringify(res))
console.log(typeof res)
})
however when I export the result
from main.js and try to bring it into another file I get an undefined
:
main.js:
const foobar = require('./foobar')
ipcMain.on('channel', (e, res) => {
console.log(JSON.stringify(res))
console.log(typeof res)
module.exports.res = res
foobar.testing()
})
foobar.js:
const res = require('./main')
module.exports = {
testing: function(res) {
console.log(`Attempting console.log test: ${res}`)
console.log(res)
console.log(JSON.stringify(res))
}
}
terminal result:
Attempting console.log test: undefined
undefined
undefined
I've also tried to redefine the object in main.js:
ipcMain.on('channel', (e, res) => {
module.exports = {
foo: foo,
bar: bar,
}
console.log(`Testing object ${res.foo}`)
foobar.testing()
})
My research of reference:
What a I doing wrong in my export of the result
in main.js so I can use it in a different file?
Edit:
My end goal is to learn how to be able to call res.foo
in foobar.js.