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

229
Visualizações
how to open node in a new terminal from cmd?

when I type start node into the cmd it starts up a new node terminal like this:

but how do I get it to run a script in the node terminal and close it after it's done?

maybe something like this?

start node "index.js" (when I try this it opens a terminal then immediately closes)

index.js:

console.log('hello there!');

await new Promise(r=>setTimeout(r,3000));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Top-level awaits aren't supported in Node versions prior to 14.18.0; there is a helpful discussion on GitHub as to why.

Since you're running v14.17.6, you'll need to wrap your code in an anonymous async function, then invoke it with ():

(async () => {
    console.log('hello there!');
    await new Promise(r=>setTimeout(r,3000));
})();

The resulting Node terminal will await for your timeout period before being closed.

(It may also behoove those reading this answer to ensure that they are correctly referencing the script they wish to execute relative to their command line's current working directory; see comment below by @cakelover.)

about 4 years ago · Juan Pablo Isaza 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