Useful runtime helpers for platform detection, module loading, and environment awareness.
import atomix from '@nasriya/atomix';
const runtime = atomix.runtime;| API | Description |
|---|---|
| getProjectName | Reads and returns the project name from the package.json |
| getModuleSystem | Dynamically loads a module by name or path |
| getRuntimeEngine | Detect the current JavaScript runtime environment. |
| loadModule | Dynamically loads a module by name or path |
| loadFileModule | Loads a module from a specified file path |
| platform | Utilities to detect current operating system |
| isNode | Detects if the code is running in Node.js |
| isBun | Detects if the code is running in Bun |
| isDeno | Detects if the code is running in Deno |
Signature: getProjectName()
Reads the package.json file and returns the value of the name field.
const name = runtime.getProjectName();
console.log(name); // "@nasriya/my-package"Signature: getModuleSystem()
Detects whether the current runtime uses CommonJS or ESM.
const system = runtime.getModuleSystem();
console.log(system); // "commonjs" or "module"Signature: loadModule(name, options?)
Dynamically loads a module (either a package or path), with support for both CommonJS and ESM.
const lodash = await runtime.loadModule('lodash');
lodash.camelCase('hello world'); // "helloWorld"Signature: loadFileModule(filePath)
Loads a module from a file path. Equivalent to loadModule(path, { isFile: true }).
const config = await runtime.loadFileModule('/absolute/path/to/config.js');
console.log(config); // loaded module exportSignature: platform.isWindows() / isLinux() / isMac()
Detects the current operating system platform.
if (runtime.platform.isWindows()) {
console.log('Running on Windows');
}Signature: getRuntimeEngine(): 'node' | 'bun' | 'deno' | 'unknown'
Detect the current JavaScript runtime environment.
const runtimeEngine = runtime.getRuntimeEngine();
console.log(runtimeEngine);
// "node", "bun", "deno", or "unknown"Signature: isNode()
if (runtime.isNode()) {
console.log('Running in Node.js');
}Signature: isBun()
if (runtime.isBun()) {
console.log('Running in Bun');
}Signature: isDeno()
if (runtime.isDeno()) {
console.log('Running in Deno');
}