11

Is it possible to modify process?

For example process.argv.push('something')?

It seems like other modules do not pick up the changes in the arguments.

I want to "trick" another module into acting like some argument was specified when the process was started.

Is process instantiated for each module on load and therefore globally immutable?

Kenneth Lynne
  • 15,461
  • 12
  • 63
  • 79
  • I did try yes, and it does not seem to be a shared instance across modules. – Kenneth Lynne Jul 11 '15 at 22:27
  • Perhaps you should expand your question, it's unclear what it is you want to accomplish. – robertklep Jul 12 '15 at 05:18
  • I want to "trick" another module into acting like some argument was specified when the process was started. – Kenneth Lynne Jul 12 '15 at 14:08
  • 2
    I don't see why that wouldn't be possible, provided that you make sure that you change `process.argv` before that module is loaded (or rather, before that module uses `process.argv`). – robertklep Jul 12 '15 at 15:17
  • Ah. Obviously. It seems like the dependency is a singleton and instantiated at an earlier stage also. I was afraid maybe process was instantiated for each module on load, and that it was not possible to modify it globally. – Kenneth Lynne Jul 12 '15 at 16:34

1 Answers1

8

You can modify process, just make sure that you do it before anything that is dependant on it loads and parses it.

Kenneth Lynne
  • 15,461
  • 12
  • 63
  • 79
  • 2
    You my friend are a savior. For my future self: Remember: process is modifiable and modify it before your other program reads it – Dheeraj Bhaskar Jan 20 '18 at 07:06