1

I have a module in node that I use to pass a username and password.

This is how it works in prompt:

node main.js --username admin --password pass

I'm trying to execute it in my node server via browser with:

const bundle = require ('./js/main.js')("--username admin --password pass")

The require runs the app but args are not working. How to fix this?

1
  • Fixed with shelljs Commented Oct 14, 2021 at 9:46

1 Answer 1

1

You can access the arguments passed in nodejs by accessing process.argv variable.

for (let i = 0; i < process.argv.length; i++) 
{
     console.log(process.argv[i])
}
Sign up to request clarification or add additional context in comments.

1 Comment

Tks pumpkinql but that is valid for the initial js that I run with node.js at beggining. This main.js is another one that I want to run/exec everytime I do /teste I need to pass the arguments in the code when a url is selected.

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.