Node.js 绝对路径
Node.js absolute path
我正在尝试构建一个 Electron 应用程序,它可以快速将机器信息拉取给用户。我正在尝试使用 npm 模块 'shelljs' 以便能够在节点环境中使用 shell 脚本。但是 Electron 并不真正支持 shelljs,所以我有点困惑。有一个解决方法,包括使用节点二进制文件的绝对路径。不知道他们的意思,所以我想你们可以帮忙。
我得到的解决方法取自 here 他们是这样说的:
Set it like any regular variable.
// This is inside your javascript file
var shell = require('shelljs');
shell.config.execPath = 'path/to/node/binary'; // Replace this with the real path
// The rest of your script...
这是我的代码,我在 execPath
:
上得到了一个 undefined
const shell = require('shelljs')
const path = require('path')
shell.confic.execPath = path.join('C:', 'Program Files', 'nodejs', 'node_modules', 'npm', 'bin')
我是否以错误的方式解释了解决方法?
@Chirag Ravindra 指出的拼写错误起到了作用。经过一番思考,我得出了这个解决方案:
shell.config.execPath = path.join('C:', 'Program Files', 'nodejs', 'node.exe')
//托马斯
我正在尝试构建一个 Electron 应用程序,它可以快速将机器信息拉取给用户。我正在尝试使用 npm 模块 'shelljs' 以便能够在节点环境中使用 shell 脚本。但是 Electron 并不真正支持 shelljs,所以我有点困惑。有一个解决方法,包括使用节点二进制文件的绝对路径。不知道他们的意思,所以我想你们可以帮忙。
我得到的解决方法取自 here 他们是这样说的:
Set it like any regular variable.
// This is inside your javascript file
var shell = require('shelljs');
shell.config.execPath = 'path/to/node/binary'; // Replace this with the real path
// The rest of your script...
这是我的代码,我在 execPath
:
const shell = require('shelljs')
const path = require('path')
shell.confic.execPath = path.join('C:', 'Program Files', 'nodejs', 'node_modules', 'npm', 'bin')
我是否以错误的方式解释了解决方法?
@Chirag Ravindra 指出的拼写错误起到了作用。经过一番思考,我得出了这个解决方案:
shell.config.execPath = path.join('C:', 'Program Files', 'nodejs', 'node.exe')
//托马斯