I’m trying to figure out how to work with the Electron. Everything works great but I have a problem.
I have:
- The electron app for a project manipulation
- A few node.js versions on my device
My actions:
- Choose a directory of a project
- Press a button which pass the project path and “yarn install” command to the main process handler.
Main handler:
import { ipcMain } from 'electron';
import { exec } from 'node:child_process';
ipcMain.handle(
'run-command',
async (
_event,
{
path,
command,
}: {
path: string;
command: string;
},
) =>
new Promise((resolve, reject) => {
exec(command, { cwd: path }, (error, stdout, stderr) => {
if (error) {
reject(new Error(`Command failed: ${command}n${stderr}`));
return;
}
resolve(stdout);
});
}),
);
But this command returns an error because of wrong node version.
I want to use the default node version of my OS (18.18.2), but the app uses old (11.5.0).
May be it’s possible to use different node.js version for any project?
I just want to run some commands for a project in its context like manually in the terminal.
Could someone explain, how can I do it? Thank you for your attention and any advices!