Making a Pear Terminal Application

This guide demonstrates how to build a peer-to-peer chat application.

It continues where Starting a Pear Terminal Project left off.

Build with Pear - Episode 04: Pear Terminal Applications

Step 1. Install modules

Install the development dependencies using:

This will install the following:

For the chat part of the app, the same modules are needed as in Making a Pear Desktop Application, hyperswarm, b4a and hypercore-crypto.

Pear runs on Bare, a lightweight JavaScript runtime which is similar to Node.js but comes with very few internal modules. Almost all Bare functionality comes from dependencies. Pear Terminal Applications are Bare applications so we will need bare-readline and bare-tty to read user input.

Step 2. JavaScript

Replace index.js with

Step 3. Run in dev mode

To test this chat app, in one terminal run pear run --dev .

The app will output something similar to:

In another terminal use this key as input, pear run --dev . a1b2c35fbeb452bc900c5a1c00306e52319a3159317312f54fe5a246d634f51a

The app will output:

Type something in one of the applications. Two Terminal Applications are now connected peer-to-peer.

Next

Last updated