osenv-modern
v1.0.0
Published
A maintained, dependency-free compatibility implementation of osenv
Maintainers
Readme
osenv-modern
osenv-modern preserves the small CommonJS API and observable behavior of the
archived osenv package while removing its
deprecated runtime dependencies. It is a compatibility package, not a new
environment-information API.
Installation
npm install osenv-modernCommonJS remains the primary interface:
var osenv = require('osenv-modern')
console.log(osenv.home())
console.log(osenv.path())Node.js can also import the CommonJS default without a separate ESM build:
import osenv from 'osenv-modern'API
hostname(callback?)returnsCOMPUTERNAMEon Windows orHOSTNAMEon Unix, with the legacyhostnamecommand fallback.user(callback?)returnsDOMAIN\\usernameon Windows orUSERon Unix, with the legacywhoamifallback.prompt(callback?)returnsPROMPTon Windows orPS1on Unix.tmpdir(callback?)returns the operating-system temporary directory.home(callback?)returns the current home directory.path(callback?)returns PATH entries as an array.editor(callback?)usesEDITOR,VISUAL, thennotepad.exe/vi.shell(callback?)usesComSpec/SHELL, thencmd/bash.
Every result is memoized after its first lookup. A callback on a memoized value
is invoked with (null, value) on process.nextTick(). See
COMPATIBILITY.md for the exact fallback edge cases and
environment precedence.
Platform and Node.js support
The package is tested on Windows, Linux, and macOS with all supported Node.js release lines: Node 22, 24, and 26 at the time of this release. The support floor advances when the oldest Node.js LTS line reaches end-of-life.
Migrating from osenv
Change the package name and keep existing calls unchanged:
- var osenv = require('osenv')
+ var osenv = require('osenv-modern')After this package is published, npm aliasing can preserve source-level imports:
{
"dependencies": {
"osenv": "npm:osenv-modern@^1.0.0"
}
}Then existing require('osenv') calls resolve to osenv-modern.
Compatibility policy and known differences
The eight public functions, CommonJS loading, environment precedence,
memoization, callback timing, fallback commands, defaults, and historical edge
cases are compatibility commitments. There are no intentional API differences
from [email protected]. Package metadata, supported Node versions, test tooling,
and the absence of os-homedir/os-tmpdir are intentionally modernized.
License
ISC. The original copyright and license are retained in LICENSE.
