What This Adds In Cloud Code
- Secure secret and config retrieval without hardcoding.
- Shared values across jobs, routes, callbacks, and functions.
- Runtime cache-backed lookups for repeated access.
Quick Start
js
const apiKey = Nimbu.Site.env.get('PARTNER_API_KEY');
const hasWebhookSecret = Nimbu.Site.env.has('WEBHOOK_SECRET');API
Nimbu.Site.env (global helper):
| Function | Params | Returns | Notes |
|---|---|---|---|
get(name) | name: string | string | null | Returns variable value or null. |
has(name) | name: string | boolean | True if key exists. |
keys() | none | string[] | Available variable names. |
require('site_variables') module export:
| Function | Params | Returns |
|---|---|---|
variable(name) | string | string | null |
has_variable(name) | string | boolean |
all_variable_names() | none | string[] |
Practical Example
js
const HTTP = require('http');
const token = Nimbu.Site.env.get('CRM_TOKEN');
if (!token) throw new Error('CRM_TOKEN missing');
HTTP.post(
'https://crm.example.com/api/subscribers',
JSON.stringify({ email: request.params.email }),
{
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
}
);Failure Modes & Gotchas
- Missing keys return
null; handle explicitly. - Do not log secret values.