UNPKG

remotevars

Version:

Carga variables de entorno desde mรบltiples providers remotos

170 lines (116 loc) โ€ข 3.29 kB
# ๐ŸŒ RemoteVars **RemoteVars** is a modern Node.js library and CLI tool that lets you manage environment variables from remote sources โ€” like GitHub, HTTP endpoints, or local JSON files โ€” eliminating the need for `.env` files in your projects. --- ## ๐Ÿš€ Features - ๐Ÿ”’ Load configuration securely from: - GitHub repositories (private or public) - HTTP(S) endpoints - Local JSON files - ๐Ÿง  Optional local cache for offline resilience - โš™๏ธ CLI tool for pulling, printing, and loading variables - ๐Ÿ’ป Works with Node.js, Express, React, or any framework - โ˜๏ธ Perfect for distributed teams and CI/CD setups --- ## ๐Ÿ“ฆ Installation ```bash npm install -g remotevars ``` or for local development: ```bash npm install remotevars --save-dev ``` --- ## ๐Ÿงฎ Usage ### 1๏ธโƒฃ Basic CLI Usage #### Pull environment variables and save them to `.env.local`: ```bash npx remotevars pull --provider=github --repo=myorg/configs --path=envs/dev.json ``` #### Load variables directly into `process.env` (in-memory): ```bash npx remotevars load --provider=http --url=https://example.com/config.json ``` #### Print variables to console (for debugging): ```bash npx remotevars print --provider=local --path=./envs/dev.json ``` #### Clear local cache: ```bash npx remotevars clear-cache ``` --- ### 2๏ธโƒฃ `.remotevars.json` Configuration File Create a `.remotevars.json` in your project root to define your preferred provider(s): ```json { "defaultProvider": "github", "useCache": true, "github": { "repo": "myorg/myconfigs", "path": "envs/dev.json", "branch": "main", "token": "ghp_XXXXXXX" }, "http": { "url": "https://example.com/config.json" }, "local": { "path": "./envs/dev.json" } } ``` --- ## โšก Disabling Cache You can disable the caching system globally or per command. ### Option 1: In the `.remotevars.json` ```json { "useCache": false } ``` ### Option 2: CLI flag ```bash npx remotevars pull --no-cache ``` When cache is disabled, RemoteVars always fetches fresh data from the provider and never stores or reads from the cache. --- ## ๐Ÿง™โ€โ™‚๏ธ Supported Providers | Provider | Description | Required Options | |-----------|--------------|------------------| | **github** | Fetch from a GitHub repository | `repo`, `path`, optional `branch`, `token` | | **http** | Fetch from any HTTP/HTTPS endpoint returning JSON | `url` | | **local** | Load from a local JSON file | `path` | --- ## ๐Ÿงฑ Programmatic Usage (Node.js API) You can also use `RemoteVars` directly in your code: ```js import { loadRemoteVars } from "remotevars"; await loadRemoteVars({ provider: "github", repo: "myorg/myconfigs", path: "envs/dev.json", token: process.env.GH_TOKEN, useCache: false }); console.log(process.env.API_KEY); ``` --- ## ๐Ÿฅช Testing Run unit tests: ```bash npm test ``` --- ## ๐Ÿ—บ๏ธ Roadmap - ๐Ÿ” Add encrypted secrets support - โ˜๏ธ Add AWS S3 and GCP provider support - ๐Ÿงฉ Add `.remotevarsrc` global configuration --- ## ๐Ÿง‘โ€๐Ÿ’ป Author Created by **Jose R. Garcia** ๐Ÿ“ฆ GitHub: [@jrgf](https://github.com/jrgf) --- ## ๐Ÿชช License MIT License โ€” feel free to use, modify, and distribute. --- **RemoteVars** โ€” *Your environment, remotely controlled.*