Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

592
Views
nodejs child process - Error: spawn node ENOENT

I'm using this code to try spawn a child process that needs to run a script.

const child = require('child_process').spawn;
const path = require('path');
const script = path.format({dir: __dirname, base: 'myscript.js'});

    child('node', [script], {
        cwd: __dirname,
        env: {
            TEST_USERNAME: 'myuser',
            TEST_PASSWORD: 'mypassword'
        }
    }).on('error', (error) => {
        console.log(error);
    });

I'm getting this error when I try to run my index.js script

Error: spawn node ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:276:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node',
  path: 'node',
  spawnargs: [ '/Users/dev/Desktop/cli-training/demo.js' ]
}

UPDATE

I'm trying to run the child script after that inquirer.js have prompted some questions to the user. Can be this the problem?I've noticed that the child process will be not executed. Inside my child script I have this code

const { IgApiClient } = require('instagram-private-api');
const chalk = require('chalk');

console.log(chalk.magenta('Starting child script'));

const ig = new IgApiClient();

console.log(process.argv);

How I can fix it?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want to execute the node binary in a child-process, it s better to refer to its full path, you can find it with process.execPath

this should fix your problem

child(process.execPath, [script], {
        cwd: __dirname,
        env: {
            TEST_USERNAME: 'myuser',
            TEST_PASSWORD: 'mypassword'
        }
    }).on('error', (error) => {
        console.log(error);
    });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!