Run node script in electron app on click button


#1

i am new to electron and node js . how aver i am try to develop electron api app to communicate with mikrotik router.
i have JavaScript file and assume that’s name = getuser.js when i run node getuser.js in command line it is ok it show out put in the terminal.
now i want to run getuser.js on click electron index.html button. please help me


#2

Electron integrates Chromium with Node.js, so you can do it the same way you would in Node, requireing it:

myButton.onclick = function() {
  require('./getuser');
};

#3

can you help me this is my code

`var api = require('mikronode');
     
var connection = new api('192.168.1.20','admin','admin');
connection.connect(function(conn) {

   var chan=conn.openChannel();
   conn.closeOnDone(true);
   chan.write('/ip/address/print',function() {
      chan.closeOnDone(true);
      chan.on('done',function(data) {

         var parsed = api.parseItems(data);

         parsed.forEach(function(item) {
            document.write('Interface/IP: '+item.interface+"/"+item.address);
         });
 
      }); 
   }); 
}); `

#4

First, you should be a bit more specific, since I don’t know anything about that API and I don’t know what’s wrong. According to the mikronode’s readme, you should probably upgrade to a version greater than 1.0.0 (if you haven’t done so already) and change new api to api.getConnection or new api.Connection.

That said, any further questions about the API you should probably ask on StackOverflow, since it doesn’t really pertain to Electron itself (and therefore isn’t relative to Atom Discuss).