Performance: execFile for running executables
MEDIUM IMPACT
This affects how quickly external programs start and complete, impacting overall app responsiveness and CPU usage.
const { execFile } = require('child_process');
execFile('myExecutable', ['arg1', 'arg2'], (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
console.log(stdout);
});const { exec } = require('child_process');
exec('myExecutable arg1 arg2', (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
console.log(stdout);
});| Pattern | Process Creation Overhead | CPU Usage | Security Risk | Verdict |
|---|---|---|---|---|
| exec with shell | High (spawns shell process) | Higher (shell parsing) | Higher (shell injection risk) | [X] Bad |
| execFile direct | Low (no shell) | Lower (direct exec) | Lower (no shell injection) | [OK] Good |