Nxpress LogoNxpressv1.3.8
06

Injected Template Variables & Objects

Nxpress automatically injects standard helper objects and variables into every view template rendering context.

1. R / req (Request Object)

A sanitized representation of the current HTTP request:

PropertyDescriptionExample Value
R.urlFull requested URL path"/products/123?sort=asc"
R.pathPathname without query string"/products/123"
R.fullFull URL string with protocol and host"http://localhost:3000/products/123"
R.baseBase URL with protocol and host"http://localhost:3000"
R.methodHTTP method in uppercase"GET"
R.queryQuery parameters object{ sort: "asc" }
R.paramsDynamic route path parameters object{ id: "123" }
R.headersHTTP request headers object{ "user-agent": "..." }
R.cookiesRequest cookies object{ session: "..." }
R.ipClient IP address"127.0.0.1"
R.protocolProtocol"http" or "https"
R.hostHost header value"localhost:3000"
R.localeCurrently active locale string"en"
R.localesArray of available locales["fr", "en", "es"]
R.defaultLocaleConfigured default locale"fr"

2. E / env (Environment Variables)

Exposes environment variables safely to view templates based on the secureEnv flag:

  • When secureEnv: true (default): Filters process.env to only include NODE_ENV and variables starting with PUBLIC_.
  • When secureEnv: false: Exposes all environment variables in process.env.
Template Access

Environment: <%= E.NODE_ENV %>

Public API Key: <%= E.PUBLIC_API_KEY %>

3. G / global & 4. $ (Component Renderer)

  • G / global: Merged object containing custom globals from configuration, all built-in helpers, and the component renderer $.
  • $ (Component Renderer): Function used inside templates to include reusable components from componentsDir.
Rendering Components in EJS
<%- $("Navbar", { activePage: "home" }) %>

5. Automatic Helpers & Assets

VariableTypeDescription
yearnumberCurrent 4-digit year (e.g. 2026).
nowDateCurrent JavaScript Date object instance.
langstringDirect current active language code in templates (e.g. 'en').