Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

416
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda