env-path-resolver
v1.0.1
Published
Cross-platform home-directory and environment variable path expander.
Maintainers
Readme
env-path-resolver
Why use env-path-resolver? File paths in configurations often contain home-directory shortcuts (
~) or environment variables ($VARor%VAR%). Node's nativepathmodule does not resolve these shortcuts, leading to broken directories and manual parsing hacks.
A cross-platform variable path expander that resolves tildes (~) and environment variables ($VAR or %VAR%) safely without launching shell processes.
⚡ Features
- Resolves user home directories (~/path)
- Expands Unix environment variables ($VAR / ${VAR})
- Expands Windows environment variables (%VAR%)
- No shell execution, zero security risks
📦 Installation
npm i env-path-resolver🚀 Usage
import { resolveEnvPath } from 'env-path-resolver';
// Resolves to e.g. "/Users/username/app/logs/prod.json"
const resolved = resolveEnvPath('~/app/logs/$ENV.json', { ENV: 'prod' });
console.log(resolved);⚙️ API Reference
resolveEnvPath(filePath, envOverride?)
filePath:string- String path to expand.envOverride:Record<string, string>- Optional overrides for environment variables.- Returns resolved absolute
stringpath.
📺 Demonstration

📄 License
MIT License.
