Reputation: 127
I've seen that the process modules can be used without importing it directly in your file as said in the documentation from 2011. https://nodejs.org/en/knowledge/getting-started/the-process-module/
The process module doesn't need to be required - it is somewhat literally a wrapper around the currently executing process, and many of the methods it exposes are actually wrappers around calls into core C libraries.
But in the documentation of Node.js v16.17.1
(the one I'm using) they actually import it without mentioning it. https://nodejs.org/docs/latest-v16.x/api/process.html#process-events
import process from 'node:process';
process.on('beforeExit', (code) => {
console.log('Process beforeExit event with code: ', code);
});
Is there even a difference between the two ? If I use the import syntax will it be referencing the current process or a different instance?
Upvotes: 5
Views: 1763
Reputation: 6491
process
is available without export. For consistency it is re-exported as a module here
Two things to keep in mind:
spawn
/exec
) return their own process object.Worker
s, within worker
body, process
returns the owner process
, as these are just threads.Upvotes: 7