print()

print() is the primary way to output content to the response body. Everything passed to print() is sent to the browser.

Syntax

print(value1, value2, ...)

Parameters

ParameterTypeDescription
valueanyOne or more values to output. Each is converted to a string.

Return Value

None (undefined).

Examples

Basic Output

print("Hello, World!");

HTML Output

print("<h1>Welcome</h1>");
print("<p>This is a paragraph.</p>");

Template Literals

const name = "Alice";
const age = 30;
print(`<p>${name} is ${age} years old.</p>`);

Multiple Values

print("Hello, ", "World", "!");

JSON Output

response.setHeader("Content-Type", "application/json");
print(JSON.stringify({ status: "ok", data: [1, 2, 3] }));

Notes

  • The default Content-Type is text/html, so HTML output is rendered by the browser
  • Multiple calls to print() append to the response body in order
  • There is no automatic newline added between calls
  • Output is buffered and sent after the script completes
Was this page helpful?