0

I've read several related questions here but still can't figure out what I'm doing wrong. Here's my script (simple.js):

    var x = process.argv[2]
    console.log(x);

now when I type in the REPL

    .load simple.js Hello

the REPL answers

 Failed to load:simple.js Hello

but I've done this (simple2.js):

    console.log(process.argv);

and when I .load this file in REPL it answers

    > console.log(process.argv);
    [ 'C:\\Program Files\\nodejs\\node.exe' ]
    undefined
1
  • Just tested it: I don't think the REPL .load is designed for this sort of thing. You probably have to use the standard node simple.js Hello in terminal. Commented Jul 5, 2016 at 17:24

2 Answers 2

1

You can't pass command line args to .load. The second case didn't fail because you didn't pass one.

If you want to use cmdline args, just use the OS terminal and enter node simple.js Hello.

Sign up to request clarification or add additional context in comments.

Comments

0

.load inside the Node REPL just loads a file. From the REPL docs it looks like the primary use case of .load is to restore a REPL session that was saved using .save.

In your succesful example its simply showing what process.argv is set to when you ran node in your terminal

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.