xPulse
πŸ‡¬πŸ‡§ EN
Pages
Contents

Guide

Installation

npm install @xpulse/config --registry=https://npm.xpulse.one

Quickstart

import config from '@xpulse/config';
await config.load();
console.log(config.name); // 'xpulse-web'
console.log(config.get('http.port')); // '3000'

What Happens on Load?

config.load() runs the following steps in order:

  1. dotenv.load() – loads .env + .env.{NODE_ENV} into process.env
  2. Read and parse xpulse.json
  3. Validate name – throws if missing
  4. Apply defaults – missing standard keys are filled with fallback values
  5. Resolve ${VAR} – all references to process.env values are replaced
  6. Emit config:loaded

Creating xpulse.json

Every project needs an xpulse.json in the repo root:

{
"name": "xpulse-web",
"type": "tool"
}

name is required – all other keys are optional and have defaults.

${ENV_VAR} References

Values in xpulse.json can reference .env variables:

{
"name": "xpulse-web",
"type": "tool",
"http": {
"port": "${PORT}"
},
"sources": {
"chat": {
"url": "${CHAT_URL}"
}
}
}
# .env
PORT=3000
CHAT_URL=https://chat.xpulse.one
await config.load();
config.get('http.port') // '3000'
config.get('sources.chat.url') // 'https://chat.xpulse.one'

Unresolvable variables remain as ${VAR} and produce a warning.

Custom Keys

xpulse.json is an open schema – custom keys are allowed and passed through without warnings:

{
"name": "xpulse-chat",
"type": "tool",
"release": {
"current": "1.3.0",
"codename": "Abomasnow"
}
}
config.get('release.current') // '1.3.0'
config.get('release.codename') // 'Abomasnow'

Events

After config.load(), config:loaded is emitted via @xpulse/event. dotenv:loaded is fired shortly before by @xpulse/dotenv.

import event from '@xpulse/event';
event.on('config:loaded', ({ name, type, env, files }) => {
console.log(`${name} (${type}) loaded – ENV: ${env}`);
});
await config.load();

Explicit Path

// Load xpulse.json from a different directory
await config.load({ path: '/app' });
// Force a specific environment
await config.load({ env: 'stage' });
en/guide.md 2026-03-13