2

The problem is that when you pass a command-line argument is passed as a string.

So when I run this node index.js [[1,2],[2,3]]

I am getting that in the process.argv

[
  '/Users/user/.nvm/versions/node/v12.13.0/bin/node',
  '/Users/user/node/index.js',
  '[[1,2],[2,3]]'
]

I can make a parser for that but I am trying to avoid that.

Is there a way to do that or I am abusing the arguments?

1 Answer 1

4

Arguments are passed as string, so you can't avoid it. You don't need to make a parser since that's a valid JSON

const arr = JSON.parse(process.argv[2])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.