Build Peer-to-Peer Applications with Pear Runtime

Rate this content
Bookmark

Learn how to rapidly build peer-to-peer applications with Pear Runtime. No servers required. Understand peer-to-peer paradigms and construct applications from well-defined building blocks. This workshop will cover how to create both Desktop and Terminal applications (with discussion for Mobile) that work entirely peer-to-peer from anywhere in the world. By the end of this workshop you should know how to build a new type of highly scalable application with entirely reduced infrastructural costs (~0) along with suitable architectures and best practices for peer-to-peer applications. From the creator of Pear Runtime and the company that brings us keet.io.

 

Table of content:

- Introducing Pear

- Initial Q & A

- Getting Setup

- Creating a Pear Desktop Application

- Sharing a Pear Application

- Running a Pear Application

- Creating a Pear Terminal Application

- Releasing a Pear Application

- Architectural Discussions

- Wrap-up Q & A

This workshop has been presented at JSNation 2024, check out the latest edition of this JavaScript Conference.

FAQ

The PAIR runtime workshop is an introduction to the PAIR platform, which enables you to manage, deploy, and create peer-to-peer applications without requiring a central service. The workshop includes seven exercises and typically lasts around three hours.

A hole punch is a component of the PAIR platform that enables you to manage, deploy, and create peer-to-peer applications. It facilitates the connection between peers without needing a central service.

To set up PAIR, you need Node.js installed on your system. For Linux or Mac users, NVM (Node Version Manager) is recommended for rapid setup. For Windows users, you can try MVS or other setup methods suitable for Windows.

You can install PAIR using Node.js by running the command 'npm install' followed by 'PAIR'. This installs a small CLI that bootstraps the rest of PAIR from peers.

The first run of PAIR may be slow on macOS due to the way macOS handles binaries. Running the command again should make it faster.

PAIR has two types of versions: the key, fork, and length version breakdown, which can be obtained using the command 'PAIR -v', and the latest changelog version, which follows the Semantic Versioning (SEMver) system and can be obtained using 'PAIR -info'.

HyperSwarm is a Distributed Hash Table (DHT) module used in the PAIR platform for building peer-to-peer applications. It enables peer discovery and connection without a central service.

The 'PAIR init' command is used to initialize a PAIR desktop application. It generates the necessary files and folders, such as app.js, index.html, package.json, and a test folder, to bootstrap a peer-to-peer desktop app.

You can run a PAIR application using the command 'PAIR run' followed by the directory path or a PAIR link. Adding the 'dev' flag enables development mode, which allows access to developer tools.

The PAIR platform is built on BEAR, a lightweight JavaScript runtime. BEAR provides first-class support for P2P primitives and is designed to be extremely small and modular.

David Mark Clements
David Mark Clements
152 min
04 Jun, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Welcome to the PAIR runtime workshop where we will build a peer-to-peer chat app and cover setup instructions for PAIR. PAIR is a platform for building peer-to-peer apps and can be used for desktop, terminal, and mobile apps. The UI is built using the telebrowser and electron platform, with plans to transition to BEAR and Chromium. PAIR offers advantages over traditional tech models, eliminates infrastructure costs, and allows for faster development. Future plans include Pair Build for creating wrapper apps, setting up identities for syncing devices, and cryptographic proof of actions taken within rooms.

1. Introduction to PAIR Workshop

Short description:

Welcome to the PAIR runtime workshop. We're going to build a peer-to-peer chat app and cover setup instructions for PAIR. You'll need Node installed and can use MVM for Linux or Mac. On Windows, use MVS or your own method.

Welcome to the PAIR runtime workshop. This is an introduction to this thing we built, which is called a hole punch, which enables you to manage, deploy, create peer-to-peer applications. No central service required at all. So, we're going to get into how to use it in different things and we're going to build a little chat app, peer-to-peer chat app.

We've got seven exercises, and they're pretty straightforward. The workshop will be either three hours or however long it takes to get through the workshop and whichever is less. And then we're done. And you'll have a ton of information. So, let's get into it. If we go to the link there, hole punch to PAIR workshop GitHub repo, there's some setup instructions. We're going to be talking about Keating this, and, Keat, you can share multiple screens. Yeah, so if you go to the repo, and we've got some setup instructions.

When you're setting up PAIR, what you're actually installing is a whole run time. So, PAIR isn't built on Node. It's built on something called BEAR, which we'll talk about later. But if you have Node installed, and you'll need Node installed to do this anyway, because once we start setting up dependencies, we use NPM install. So, if you don't have Node installed, get that installed now. If you're on Linux or Mac, MVM is good for a rapid setup. MVM.sh will take you there. And on Windows, well, on Windows, do what you do. You can try MVS, but if you've, this one, you can't do that, because you don't have the basic interface in GNNVS. But if you've, or Jen, sorry, if you've, you know, if you're a Windows user, this might work for you, or, you know, do it your own way. So, let's take a moment to go through the setup.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

How Bun Makes Building React Apps Simpler & Faster
React Day Berlin 2022React Day Berlin 2022
9 min
How Bun Makes Building React Apps Simpler & Faster
BUN is a modern all-in-one JavaScript runtime environment that achieves new levels of performance. It includes BUN dev, a fast front-end dev server, BUN install, a speedy package manager, and BUN run, a fast package runner. BUN supports JSX, has optimized React server-side rendering, and offers hot module reloading on the server. The priorities for BUN include stability, node compatibility, documentation improvement, missing features in BUN install, AST plugin API, native Windows support, Bundler and Minifier optimization, and easier deployment to production. BUN's AST plugin API allows for bundle-time JavaScript execution and embedding code, potentially inspiring new frameworks.
Node.js Compatibility in Deno
Node Congress 2022Node Congress 2022
34 min
Node.js Compatibility in Deno
Deno aims to provide Node.js compatibility to make migration smoother and easier. While Deno can run apps and libraries offered for Node.js, not all are supported yet. There are trade-offs to consider, such as incompatible APIs and a less ideal developer experience. Deno is working on improving compatibility and the transition process. Efforts include porting Node.js modules, exploring a superset approach, and transparent package installation from npm.
Bun, Deno, Node.js? Recreating a JavaScript runtime from Scratch - Understand magic behind Node.js
Node Congress 2023Node Congress 2023
29 min
Bun, Deno, Node.js? Recreating a JavaScript runtime from Scratch - Understand magic behind Node.js
The Talk explores the magic behind Node.js and delves into its components, including V8, libuv, and the C++ bridge. It discusses the workflow and execution process, the use of NodeMod, and the understanding of console functions. The Talk also covers Node.js functions and scheduling, the introduction of runtimes, and the collaboration between JavaScript runtimes. It concludes with insights on content production, the choice of Node.js, and the inspiration behind it.
Eval all the strings! - Hardened JavaScript
Node Congress 2023Node Congress 2023
8 min
Eval all the strings! - Hardened JavaScript
NPM packages can be potentially dangerous, so it's important to be proactive in managing them. Lava Mode allows you to detect and investigate suspicious packages before deploying your app. Lavamote prevents unauthorized access to sensitive resources by isolating dependencies and using hardened JavaScript. Lava Mode makes it easier to analyze obfuscated files and understand their actions.
The Future of JavaScript Runtimes
Node Congress 2022Node Congress 2022
34 min
The Future of JavaScript Runtimes
Today's Talk explores the future of JavaScript runtimes, their evolution, and impact on software development. It discusses the historical trends of JavaScript, the adoption of new tools and libraries, and the convergence of Node and Deno. The emergence of isolate clouds and their potential to replace traditional VMs and containers is also highlighted. Additionally, the talk touches on the possibilities of JavaScript in exotic use cases, its impact on machine learning, and the potential for TypeScript to become the de facto language for JavaScript development.
Roll you own JavaScript runtime
Node Congress 2023Node Congress 2023
21 min
Roll you own JavaScript runtime
This Talk introduces Deno, a custom JavaScript runtime similar to Node.js, and discusses the benefits of using a custom runtime. It explores the process of building a custom runtime with Deno in Rust, including the integration with Cargo and the ability to mix and match crates and APIs. The Talk also covers the implementation of the setTimeout function in both Run.js and Runtime.js, and provides examples of how to fix errors and implement additional functions. Overall, the Talk highlights the flexibility and possibilities of creating custom runtimes with Deno.