错误:命令失败:哪个节点

时间:2018-08-21 13:35:29

标签: javascript node.js linux bash

我正在构建一个基本上是Heroku克隆的应用程序。我不在试图使其跨平台的过程中。我遇到的麻烦之一是在linux上找到正确的节点路径。我的意思是,每当execSync('哪个节点')获取节点路径时,我的应用程序就会在运行时崩溃。 我在该服务器应用程序的客户端make中使用了相同的命令,并且效果很好。

Wrapper running on port 2999
child_process.js:640
    throw err;
    ^

Error: Command failed: which node
    at checkExecSyncError (child_process.js:600:11)
    at Object.execSync (child_process.js:637:13)
    at Object.<anonymous> (/home/xxxx/Documents/CODE/javascript/deployment-server/dist/server.js:13:34)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)

interface PATHS {
    node: string;
    npm: string;
}
const PATHS: PATHS = {
    node: 'node',
    npm: 'npm'
};
if (process.platform == 'linux') {
    PATHS.node = execSync('which node')
        .toString()
        .slice(0, -1);
    PATHS.npm = execSync('which npm')
        .toString()
        .slice(0, -1);
} else if (process.platform == 'win32') {
    PATHS.node = execSync('where node')
        .toString()
        .slice(0, -1);
    PATHS.npm = execSync('where npm')
        .toString()
        .slice(0, -1);
}

0 个答案:

没有答案