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

411
Views
Series of node commands hangs on npx command

I have a node script whose job is to scaffold an app I've built. It creates files and folders then runs a series of node commands. All works perfectly. These are the commands that are run:

const postInstCmds = [
    'npm init -y',
    'npm install http-server --save-dev',
    'npx add-npm-scripts server "http-server"',
    'npm run server'
];
postInstCmds.forEach(cmd => execSync(cmd, {cwd: appDir}));
console.log('Done!');

However, in the terminal, it seems to hang on the penultimate (npx) command, even though it does run the final npm run server command (because the created app is available on localhost:8080). For presumably the same reason I never see my "Done!" log. This is what I see:

enter image description here

How can I get the terminal to complete the commands without hanging on the npx one?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You never see "Done" because the last command never exits. The penultimate command does in fact exit. We know this because otherwise the last command wouldn't run (since you are using execSync() and that will block until the command exits) and you would not have your server running.

What appears to be happening is that you are only seeing STDERR and not STDOUT. Without seeing the rest of your code, I can't say exactly why that is happening, but a potential easy fix could be to specify that all stdio should be inherited.

postInstCmds.forEach(cmd => execSync(cmd, {cwd: appDir, stdio: 'inherit'}));
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!