📜  Node.js process.execPath 属性

📅  最后修改于: 2022-05-13 01:56:33.279000             🧑  作者: Mango

Node.js process.execPath 属性

process.execArgv 属性是 process 模块的内置应用程序编程接口,用于获取启动 node.js 进程的 node.js 可执行文件的绝对路径名。
句法:

process.execArgv

返回值:此属性返回一个字符串,表示启动 node.js 进程的 node.js 可执行文件的绝对路径。
下面的示例说明了在 Node.js 中process.execPath 属性的使用:
示例 1:

javascript
// Node.js program to demonstrate the   
// process.execPath property
 
// Include process module
const process = require('process');
 
// Printing process.execPath
console.log(process.execPath);


javascript
// Node.js program to demonstrate the   
// process.execPath property
 
// Include process module
const process = require('process');
 
// Include path module
const path = require('path');
  
// Printing process.execPath
var execpath = process.execPath
console.log(execpath);
 
// Separated directories and file
console.log(execpath.split(path.sep));


输出:

C:\Program Files\nodejs\node.exe

示例 2:

javascript

// Node.js program to demonstrate the   
// process.execPath property
 
// Include process module
const process = require('process');
 
// Include path module
const path = require('path');
  
// Printing process.execPath
var execpath = process.execPath
console.log(execpath);
 
// Separated directories and file
console.log(execpath.split(path.sep));

输出:

C:\Program Files\nodejs\node.exe
[ 'C:', 'Program Files', 'nodejs', 'node.exe' ]

注意:上面的程序将使用 node filename.js 命令编译和运行。
参考: https://nodejs.org/api/process.html#process_process_execpath