Open In App

Node.js process.execPath Property

Last Updated : 28 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The process.execPath property is an inbuilt application programming interface of the process module which is used to get the absolute pathname of the node.js executable which started the node.js process.
Syntax: 
 

process.execPath

Return Value: This property returns a string signifies the absolute path of the node.js executable which started the node.js process.
Below examples illustrate the use of process.execPath property in Node.js:
Example 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);


Output: 
 

C:\Program Files\nodejs\node.exe

Example 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));


Output: 
 

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

Note: The above program will compile and run by using the node filename.js command.
Reference: https://nodejs.org/api/process.html#process_process_execpath
 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads