how can i run this script in html?

159 Views Asked by At

I create a b.js script file like below. when i run this using node.exe program then it correctly open "word2code.exe" file. How can i add this script in a .html page (as link or button onclick event) in appjs for windows?

var exec = require('child_process').execFile;
var fun =function(){
   console.log("fun() start");
     exec('word2code.exe', function(err, data) {  
     console.log(err)
    console.log(data.toString());                       
  });  
}
fun();
2

There are 2 best solutions below

0
On

You cannot run an exe directly on the client side in an HTML page -- the browser cannot understand binaries. Instead, if you basically want to fire off a process like this, you could take another approach:

  • Build a website that has a button.
  • This button, when clicked, should make a request to your server on some URL (like /execute).
  • Write a separate web server process on your windows machine, that runs the web server.
  • Write a route on your web server that handles /execute requests.
  • Make this route run your exe file LOCALLY ON YOUR SERVER when the route is executed.

By doing things this way, you're essentially allowing a web user to run an exe indirectly (your server will be the one running the binary, not the user).

0
On

Node.js runs on the server. The browser is on the client side. You cannot execute a nodejs app from the browser as the environment does not support nodejs.