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:
| Property | Description | Example Value |
|---|---|---|
| R.url | Full requested URL path | "/products/123?sort=asc" |
| R.path | Pathname without query string | "/products/123" |
| R.full | Full URL string with protocol and host | "http://localhost:3000/products/123" |
| R.base | Base URL with protocol and host | "http://localhost:3000" |
| R.method | HTTP method in uppercase | "GET" |
| R.query | Query parameters object | { sort: "asc" } |
| R.params | Dynamic route path parameters object | { id: "123" } |
| R.headers | HTTP request headers object | { "user-agent": "..." } |
| R.cookies | Request cookies object | { session: "..." } |
| R.ip | Client IP address | "127.0.0.1" |
| R.protocol | Protocol | "http" or "https" |
| R.host | Host header value | "localhost:3000" |
| R.locale | Currently active locale string | "en" |
| R.locales | Array of available locales | ["fr", "en", "es"] |
| R.defaultLocale | Configured 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
| Variable | Type | Description |
|---|---|---|
| year | number | Current 4-digit year (e.g. 2026). |
| now | Date | Current JavaScript Date object instance. |
| lang | string | Direct current active language code in templates (e.g. 'en'). |