您可能想研究几个 api,看看哪些对您有帮助。
fs
该fs
模块允许您直接打开文件进行读写。
var fs = require('fs');
fs.readFile(p, 'utf8', function (err, data) {
if (err) return console.log(err);
// data is the contents of the text file we just read
});
小路
该path
模块允许您以与平台无关的方式构建和解析路径。
var path = require('path');
var p = path.join(__dirname, '..', 'game.config');
壳
该shell
api 是一个纯电子 api,您可以使用它在给定路径上执行文件,这将使用操作系统默认应用程序打开文件。
const {shell} = require('electron');
// Open a local file in the default app
shell.openItem('c:\\example.txt');
// Open a URL in the default way
shell.openExternal('https://github.com');
子进程
假设您的 golang 二进制文件是可执行文件,那么您将使用child_process.spawn
它来调用它并与之通信。这是一个节点 API。
var path = require('path');
var spawn = require('child_process').spawn;
var child = spawn(path.join(__dirname, '..', 'mygoap.exe'), ['game.config', '--debug']);
// attach events, etc.
添加在
如果您的 golang 二进制文件不是可执行文件,那么您将需要制作一个本机插件包装器。