From 01810fbe0b7b498b0301baa7d990fe59c77f724d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 18 Apr 2026 10:35:21 -0300 Subject: [PATCH 1/6] src: add setTitle() as alternative to direct assignment Implement process.setTitle(title) as a new function-based API for setting the process title, complementing the existing process.title property assignment pattern Fixes: https://github.com/nodejs/node/issues/62797 Signed-off-by: Jonathan Lopes --- doc/api/process.md | 27 +++++++++++++++++++ .../switches/does_not_own_process_state.js | 1 + .../switches/does_own_process_state.js | 6 +++++ src/node_process_methods.cc | 12 +++++++++ test/es-module/test-esm-process-set-title.mjs | 27 +++++++++++++++++++ test/parallel/test-setproctitle.js | 12 ++++++++- .../test-worker-unsupported-things.js | 2 +- 7 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 test/es-module/test-esm-process-set-title.mjs diff --git a/doc/api/process.md b/doc/api/process.md index fe5ecbd3d45b..d1cf47eb61c5 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -4336,6 +4336,32 @@ Assigning a value to `process.title` might not result in an accurate label within process manager applications such as macOS Activity Monitor or Windows Services Manager. +## `process.setTitle(title)` + + + +* `title` {string} + +Sets the process title. This is equivalent to assigning a string to +[`process.title`][]. See [`process.title`][] for restrictions and platform +limitations. + +```mjs +import { setTitle } from 'node:process'; + +setTitle('my-service'); +``` + +```cjs +const { setTitle } = require('node:process'); + +setTitle('my-service'); +``` + +This function is not supported in [`Worker`][] threads. + ## `process.traceDeprecation` + +Type: Documentation-only + +The `process.title` property is deprecated. Use [`process.getTitle()`][] to +read the current title and [`process.setTitle()`][] to change it. + [DEP0142]: #dep0142-repl_builtinlibs [DEP0156]: #dep0156-aborted-property-and-abort-aborted-event-in-http [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf @@ -4815,7 +4829,9 @@ calling or overriding `_listen2`. [`process.exit()`]: process.md#processexitcode [`process.exitCode`]: process.md#processexitcode_1 [`process.getActiveResourcesInfo()`]: process.md#processgetactiveresourcesinfo +[`process.getTitle()`]: process.md#processgettitle [`process.mainModule`]: process.md#processmainmodule +[`process.setTitle()`]: process.md#processsettitletitle [`punycode`]: punycode.md [`readable.readableEnded`]: stream.md#readablereadableended [`request.abort()`]: http.md#requestabort diff --git a/doc/api/process.md b/doc/api/process.md index 64762c661e27..e4e86a88514f 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -4315,8 +4315,12 @@ argument to the function, to get a diff reading. +> Stability: 0 - Deprecated. Use [`process.getTitle()`][] to read the title +> and [`process.setTitle()`][] to change it. + * Type: {string} The `process.title` property returns the current process title (i.e. returns @@ -4338,6 +4342,17 @@ Services Manager. As an alternative to direct assignment, use [`process.setTitle()`][]. +## `process.getTitle()` + + + +* Returns: {string} + +Returns the current process title. This is equivalent to reading +[`process.title`][]. + ## `process.setTitle(title)`