Jose CastilLo Stronghold Jose CastilLo Stronghold - 1 year ago 110
Javascript Question

Share dynamic variables between JS files in Electron/Node

I'm trying to get variables between files in an Electron App.

In index.html there's a input and a button, where i post an url.

//function.js

$('#tab_url').submit(function (ev) {
ev.preventDefault();
var url = $("#url").val();
console.log(url);
if (url.indexOf('google.com') < 0) {
message('no google', 'error this is no google');
return false;
}else {
require('./apis/google');
}


I want to do something like this.

//apis/google.js
console.log(url);

Answer Source

This is more of a node.js question but basically apis/google.js needs to look like this

module.exports = (url) => {
    console.log(url);
}

And then function.js should look like this

$('#tab_url').submit(function (ev) {
  ev.preventDefault();
  var url = $("#url").val();
  console.log(url);
  if (url.indexOf('google.com') < 0) {
    message('no google', 'error this is no google');
    return false;
  } else {
    require('./apis/google')(url);
  }
})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download