Group related logs with console.group
Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.
When a request handler logs ten lines, the output is hard to read. console.group prints a label and indents everything after it until console.groupEnd.
console.group("Request");
console.log("start");
console.group("Query");
console.log("SELECT 1");
console.groupEnd();
console.log("done");
console.groupEnd();Request
start
Query
SELECT 1
doneGroups nest, and each level adds two spaces in Node.js. In a browser, the group is collapsible, and console.groupCollapsed starts it closed, which keeps noisy detail out of the way until you open it. The methods are in the Node.js console docs.
Always match each group with a groupEnd. If code throws between them, the indentation stays for every later log, so close the group in a finally block when the code can fail.
Groups only indent text. They do not tie logs to a request across async calls, so use a request id for that.