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

239
Visualizações
special characters like asterisks argv

Running my script like the following:

Node index.js POST *

In my script I do this:

process.argv.forEach((val, index) => {
  console.log(`${index}: ${val}`);
});

The output will be the following where * causes to dump all my files' names in my project:

$ node index.js POST *
0: C:\Program Files\nodejs\node.exe
1: C:\Users\myComputer\myScript\index.js
2: POST
3: commands
4: data.json
5: index.js
6: node_modules
7: package-lock.json
8: package.json

How can I see if passed arg is an astricts?

It works perfectly fine for other args like other strings (in my example 'POST').

I also used https://github.com/tj/commander.js and the same issue.

Using Node version 15

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you're running this in bash or some similar shell, then the globbing is happening on a shell level, before it ever gets to your program. You can't see whether a star was typed from inside the program, because the shell switches it out for a list of all the files in the directory.

If you want to pass an actual star, you can put it in quotes, and that way the shell won't expand it to all the files, and will pass it to the program as is.

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