I have a node script which runs Webdriver tests. I am using following code
const procInfo = child_process.spawn('wdio',
0,
pathModule.join(downloadDir, 'node_modules', '.bin', IsWin32 ? 'wdio.cmd' : 'wdio'),
args, {
cwd: downloadDir,
env: env,
detached: !IsWin32,
stdio: ['ignore', 'pipe', 'pipe']
});
I have nvm installed as well. My main process is started with node v14. I want to let user decide from the interface which node version they want to run.
How can I make child_process to use different version of node like v10
Solved it by changing the path in environment
Below is complete solution
const IsWin32 = process.platform === 'win32';
const env = process.env;
if(IsWin32)
env.Path = '/home/testable/.nvm/versions/node/v10.24.1/bin' + pathModule.delimiter + env.Path;
else
env.PATH = 'C:\\ProgramData\\nvm\\v10.24.1\\' + pathModule.delimiter + env.PATH;
const procInfo = child_process.spawn('wdio',
0,
pathModule.join(downloadDir, 'node_modules', '.bin', IsWin32 ? 'wdio.cmd' : 'wdio'),
args, {
cwd: downloadDir,
env: env,
detached: !IsWin32,
stdio: ['ignore', 'pipe', 'pipe']
});