I can't seem to be running the most trivial of scripts in node:
Platform: windows 10
node -v: v10.7.0
file: "sample.js"
process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`);
});
command line:
D:\temp>node sample.js 1 2 3
D:\temp\sample.js:4
process.argv.forEach((val, index) => {
^
TypeError: Cannot read property 'forEach' of undefined
at Object.<anonymous> (D:\temp\sample.js:4:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
The process. argv() method is used for returning all the command-line arguments that were passed when the Node. js process was being launched. The first element will always contains the same value as process. execPath.
The 'uncaughtException' is an event of class Process within the process module which is emitted when an uncaught JavaScript exception bubbles all the way back to the event loop. Parameters: This event does not accept any argument as a parameter.
Simpler, you can call process. kill('SIGSTOP') to pause the process and and process. kill('SIGCONT') to resume it.
Solution
I figured out, that I defined the function process below, that's why process object was overridden by my own.
So, to resolve:
Check that you are not overriding "process" object with a function
Put it initialization higher line by line and find what code is overriding it
Old suggestion:
In my case, it was "redefined" even if I put it on the first line. "Process" was a function.
To retrieve Object I used explicit call:
const process = require('process');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With