globalThis.process, node:process, process et elide:process désignent le
même objet.
Les propriétés Node courantes sont disponibles, notamment argv, execArgv,
env, arch, platform, pid, ppid, version, versions, execPath,
title, cwd(), umask(), exitCode et exit().
console.log(process.platform, process.arch);
console.log(process.cwd());
if (process.env.CI) process.exitCode = 1;Événements et planification
process est un EventEmitter. Il prend en charge les méthodes d’écoute
standard et les événements d’exécution tels que warning, beforeExit, exit
et uncaughtException.
process.nextTick(callback, ...args) s’exécute avant les callbacks des Promise
et de queueMicrotask au point de contrôle suivant :
const order = [];
process.nextTick(() => order.push("tick"));
Promise.resolve().then(() => order.push("promise"));
queueMicrotask(() => order.push("microtask"));
setImmediate(() => console.log(order));
// ["tick", "promise", "microtask"]Flux standard
stdin, stdout et stderr sont des flux Node. stdout et stderr exposent
leur descripteur de fichier via fd ; les flux de terminal exposent aussi les
champs TTY. La sortie de la console passe par ces flux : remplacer
process.stdout.write intercepte donc la sortie de console.log.
Environnement
process.env expose l’environnement visible sous la forme d’un objet
modifiable. Consultez Variables d’environnement pour le
chargement, la modification et le comportement vis-à-vis des sous-processus.
Métriques partielles
hrtime(), cpuUsage(), memoryUsage() et uptime() sont appelables.
cpuUsage() et memoryUsage() renvoient des objets vides : ne vous fiez donc
pas aux champs de métriques détaillés de Node. process.send et
process.disconnect sont disponibles dans un processus enfant démarré avec
child_process.fork().
Reference
Status: Partial · 77 of 87 suite tests pass (88.5%) · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
process.arch | property | Full | CPU architecture of the process (e.g. “x64”, “arm64”) |
process.argv | property | Full | Command-line arguments passed to the process, starting with the node executable path |
process.argv0 | property | Full | The original value of argv[0] before any modification by Node.js |
process.env | property | Full | Object containing the process environment variables |
process.execArgv | property | Full | Node.js-specific flags passed to the node executable |
process.execPath | property | Full | Absolute path of the node executable |
process.pid | property | Full | Process ID |
process.ppid | property | Full | Parent process ID |
process.platform | property | Full | Operating system platform (e.g. “linux”, “darwin”, “win32”) |
process.title | property | Full | Displayed process title (settable in most environments) |
process.version | property | Full | Node.js version string (e.g. “v20.0.0”) |
process.versions | property | Full | Object mapping dependency names to their version strings |
process.abort() | function | Full | Terminates the process immediately with a core dump (SIGABRT) |
process.cwd() | function | Full | Returns the current working directory of the process |
process.chdir() | function | Full | Changes the current working directory of the process |
process.exit() | function | Full | Terminates the process with the given exit code |
process.getuid() | function | Full | Returns the numeric user ID of the process owner |
process.getgid() | function | Full | Returns the numeric group ID of the process owner |
process.geteuid() | function | Full | Returns the effective numeric user ID |
process.getegid() | function | Full | Returns the effective numeric group ID |
process.hrtime() | function | Full | Returns the current high-resolution time as [seconds, nanoseconds] |
process.umask() | function | Full | Gets or sets the file creation mode mask |
process.cpuUsage() | function | Full | Returns the CPU time used since an optional reference point |
process.memoryUsage() | function | Full | Returns a snapshot of the current process memory usage |
process.uptime() | function | Full | Returns the number of seconds the current process has been running |
process.nextTick() | function | Full | Schedules a callback to run after I/O events but before timers in the current event loop tick |
process.stdin | property | Full | Readable stream connected to stdin |
process.stdout | property | Full | Writable stream connected to stdout |
process.stderr | property | Full | Writable stream connected to stderr |
Not implemented
addUncaughtExceptionCaptureCallback, debugPort, finalization, getBuiltinModule, report, resourceUsage, sourceMapsEnabled.
Tests: node-api node:process: 77 pass, 10 fail, 0 error, 6 skipped. Failing: test-process-dlopen-error-message-crash.js, test-process-env-allowed-flags-are-documented.js, test-process-env-allowed-flags.js, test-process-exec-argv.js, test-process-execve-permission-fail.js, test-process-exit-code-validation.js, test-process-load-env-file.js, test-process-remove-all-signal-listeners.js, and 2 more.