The `pear-api` package provides the foundational base class for interacting with the Pear API, which is part of the Holepunch peer-to-peer (P2P) runtime and development platform. Currently at version 1.30.0, this library enables developers to build P2P applications, particularly focusing on User Interface integrations by abstracting complex underlying P2P mechanisms. The Pear ecosystem is actively maintained, with regular updates to its 1.x branch and a significant transition underway to a version 2, which introduces notable breaking changes and a shift towards modern JavaScript module standards. Key differentiators include its focus on enabling local-first, offline-first P2P applications and its design for extensibility within UI environments like Electron.
npm install pear-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to extend the `PearAPI` base class to create a custom P2P application API, handle connection, and publish data, including error handling and simulated asynchronous operations.
Refer to the official Pear v2 Migration Guide (https://docs.pears.com/api/migration) for detailed steps, including updating your `package.json` entrypoint and adapting to new module structures like `pear-electron` and `pear-bridge`.
Transition to using the `pear-runtime` module in your application code for starting and managing the Pear runtime, or consult documentation for the appropriate CLI alternatives for development and deployment.
Ensure your project is configured for ESM. This often means setting `"type": "module"` in your `package.json`, using `.mjs` file extensions, and updating all `require()` statements to `import` statements. For TypeScript, configure `"module": "NodeNext"` or `"moduleResolution": "NodeNext"` in `tsconfig.json`.
Implement proper teardown logic using `Pear.teardown(cb)` and ensure all long-lived resources like Hyperswarm instances (`swarm.destroy()`) or worker pipes (`pipe.end()`) are gracefully closed to prevent resource leaks or application hangs. Refer to Pear troubleshooting documentation for common patterns.
Always instantiate the `PearAPI` class (or its subclasses) using `new`, e.g., `const api = new PearAPI();` or `class MyAPI extends PearAPI { ... }` then `new MyAPI();`.Verify that your module import statement is correct (`import { PearAPI } from 'pear-api';`). If you are in a CommonJS context and need an ESM-only module, consider migrating your project to ESM or using dynamic `import()` within an `async` function.Ensure that your API key or token is correctly provided during the `PearAPI` constructor or connection method. Double-check its validity, expiration, and required permissions according to your Pear API provider's documentation. Use environment variables for sensitive credentials.
No dependency data recorded yet.