{"id":10560,"library":"bare-os","title":"Bare OS Utilities","description":"bare-os provides essential operating system utilities tailored for the `bare` JavaScript runtime, a lightweight and modular environment designed for peer-to-peer applications across desktop and mobile devices. Unlike Node.js, the `bare` runtime emphasizes a minimal core, relying on modular userland libraries like `bare-os` for functionalities typically found in a standard library. Currently at version 3.8.7, the package exhibits active development, with recent updates and a healthy maintenance status. It is a key component within the Holepunch ecosystem, focusing on efficiency and cross-platform compatibility, particularly for networked applications requiring direct user-to-user connections without traditional servers. The library ships with TypeScript types, ensuring robust development experiences.","status":"active","version":"3.8.7","language":"javascript","source_language":"en","source_url":"https://github.com/holepunchto/bare-os","tags":["javascript","typescript"],"install":[{"cmd":"npm install bare-os","lang":"bash","label":"npm"},{"cmd":"yarn add bare-os","lang":"bash","label":"yarn"},{"cmd":"pnpm add bare-os","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required runtime environment, not compatible with Node.js directly.","package":"bare","optional":false}],"imports":[{"note":"ESM is the preferred import style. Type declarations are included.","wrong":"const os = require('bare-os'); os.platform();","symbol":"platform","correct":"import { platform } from 'bare-os';"},{"note":"bare-os exports named functions, not a default object. Destructure directly.","wrong":"import os from 'bare-os'; os.homedir();","symbol":"homedir","correct":"import { homedir, tmpdir } from 'bare-os';"},{"note":"CommonJS `require` works, but named destructuring is cleaner than accessing properties directly.","wrong":"const totalmem = require('bare-os').totalmem;","symbol":"totalmem","correct":"const { totalmem } = require('bare-os');"}],"quickstart":{"code":"import { platform, arch, homedir, totalmem, freemem, uptime } from 'bare-os';\n\nasync function getSystemInfo() {\n  console.log(`\n--- System Information ---\n`);\n  console.log(`Platform: ${platform()}`);\n  console.log(`Architecture: ${arch()}`);\n  console.log(`Home Directory: ${homedir()}`);\n  \n  const totalMemoryBytes = totalmem();\n  const freeMemoryBytes = freemem();\n  console.log(`Total Memory: ${(totalMemoryBytes / (1024 ** 3)).toFixed(2)} GB`);\n  console.log(`Free Memory: ${(freeMemoryBytes / (1024 ** 3)).toFixed(2)} GB`);\n\n  const systemUptimeSeconds = uptime();\n  const hours = Math.floor(systemUptimeSeconds / 3600);\n  const minutes = Math.floor((systemUptimeSeconds % 3600) / 60);\n  console.log(`System Uptime: ${hours}h ${minutes}m`);\n  console.log(`\n--------------------------\n`);\n}\n\ngetSystemInfo().catch(console.error);","lang":"typescript","description":"Demonstrates importing and using several core OS utility functions like `platform`, `homedir`, and `totalmem`."},"warnings":[{"fix":"Ensure your application is running in a `bare` environment. For Node.js compatibility with `os` module functions, consider using `bare-node-os` (installed as `os@npm:bare-node-os`).","message":"`bare-os` is specifically designed for the `bare` JavaScript runtime and is not directly compatible with Node.js or browser environments.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Refer to the `bare` runtime documentation for specific compile options and ensure your `bare` runtime version is tested and stable for your application's use case.","message":"The `bare` runtime's compile options, which can influence underlying behaviors, are not covered by semantic versioning and may change without warning, potentially affecting `bare-os` behavior.","severity":"gotcha","affected_versions":"*"},{"fix":"Use named imports for ESM (`import { funcName } from 'bare-os'`) and destructuring for CJS (`const { funcName } = require('bare-os'`) to correctly access the desired utilities.","message":"The `bare-os` module exports named functions directly. Attempting to import it as a default export or access properties on a `require`'d object without destructuring can lead to undefined errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Correct your import/require statement: `import { platform } from 'bare-os';` or `const { platform } = require('bare-os');`","cause":"Attempting to access a property on an undefined `os` object, likely due to incorrect ESM default import or CJS non-destructured `require`.","error":"TypeError: Cannot read properties of undefined (reading 'platform')"},{"fix":"Install the package via `npm i bare-os` and ensure you are running your application in the `bare` runtime environment.","cause":"The package `bare-os` is either not installed or the runtime environment does not recognize it.","error":"Error: Module not found: Can't resolve 'bare-os'"}],"ecosystem":"npm"}