简体   繁体   中英

How to run an executable on client-side using Node.js?

Is there a way to call an external program on client side and "talk" to it?

For example, if I have a Node.js serverving an AngularJS or any other framework, I want the user to press a button on the browser and a previously installed program on client-side starts to run and send back to the client some messages...

Can I achieve that?

Browsers cannot run executables on the local machine without explicit configuration as such behaviour would violate security restrictions.

Node.js can do anything that is permitted by the environment (eg user permissions) in which it is run. See: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

Consider using Native Client

Native Client is a sandbox for running compiled C and C++ code in the browser efficiently and securely, independent of the user's operating system. Portable Native Client extends that technology with architecture independence, letting developers compile their code once to run in any website and on any architecture with ahead-of-time (AOT) translation.

In short, Native Client brings the performance and low-level control of native code to modern web browsers, without sacrificing the security and portability of the web.

https://developer.chrome.com/native-client

I think that the better form to do that is using API REST, you can create your server API in node JS for example and use AngularJS to consume that services in the browser and JAVA or .NET for the Desktop app

the following is a simple Example using Node and Angular

This is certainty possible in many different ways.

One sort is using node webkit.

Another,a NPM package called Edge. This is sort of like a bridge between node a .net. Or more specifically node and a clr process. You can execute c# statements and load assemblies in a clr process and interact with it in javascript via node and Edge.

https://github.com/tjanczuk/edge

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM