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

235
Views
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 answers
Answer question

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 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!