whatisgithub

What is peerjs?

peers/peerjs — explained in plain English

Analysis updated 2026-06-24

13,327TypeScriptAudience · developerComplexity · 2/5Setup · moderate

In one sentence

A JavaScript library that connects two browsers directly to each other for real-time data, audio, or video transfer, no server relay needed once the connection is established, using WebRTC built into modern browsers.

Mindmap

mindmap
  root((PeerJS))
    Connection Types
      Data connections
      Media connections
    How It Works
      WebRTC core
      PeerServer handshake
      Direct P2P after
    Use Cases
      Video calls
      File sharing
      Multiplayer games
    Setup
      npm install
      PeerServer needed
      Modern browsers only
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Build browser-to-browser video calls without paying for media relay servers, using each browser's built-in WebRTC support.

USE CASE 2

Create a multiplayer game or collaborative tool where game state flows directly between players' browsers with low latency.

USE CASE 3

Let users share files directly between two browsers without uploading them to a server first.

What is it built with?

TypeScriptJavaScriptWebRTC

How does it compare?

peers/peerjsdanielmiessler/personal_ai_infrastructuretinacms/tinacms
Stars13,32713,33413,334
LanguageTypeScriptTypeScriptTypeScript
Setup difficultymoderatemoderatemoderate
Complexity2/53/53/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires a PeerServer instance (self-hosted or cloud) to broker the initial connection between peers before direct communication begins.

So what is it?

PeerJS is a JavaScript library that makes it straightforward to connect two browsers directly to each other without routing all data through a server. This technique is called peer-to-peer communication, and it is built on top of WebRTC, a technology built into modern browsers that allows direct audio, video, and data transfer between devices. The library supports two kinds of connections. Data connections let two browsers send arbitrary data back and forth: text, files, objects, or any other structured information. Media connections let two browsers share live audio and video streams, which is what you would use to build a video call or voice chat feature. Both work through the same simple API: you create a Peer object with an ID, connect to another peer by its ID, and then send or receive data through the resulting connection object. Behind the scenes, PeerJS uses a small server called PeerServer to handle the initial handshake between peers, because two browsers cannot find each other without some way to exchange connection details. Once connected, the actual data flows directly between browsers without passing through the server, which keeps latency low and avoids server bandwidth costs for the data itself. PeerServer is a separate open-source project that you can self-host or use as a cloud service. The library is written in TypeScript, installable via npm or yarn, and works in Firefox 80+, Chrome 83+, Edge 83+, and Safari 15+. The README includes short code examples for both data and media connections, and the project has a live demo on Glitch showing a video call application built with PeerJS. PeerJS is open source and funded through Open Collective. It is maintained by the peers organization on GitHub and has an active Discord community for questions and roadmap discussions.

Copy-paste prompts

Prompt 1
Using PeerJS, write the JavaScript code for a simple video call between two browser tabs where each user enters the other's peer ID to connect.
Prompt 2
Show me how to send a JSON object from one PeerJS client to another using a data connection and handle it on the receiving side.
Prompt 3
How do I set up a self-hosted PeerServer on Node.js and configure PeerJS clients to use it instead of the default cloud service?
Prompt 4
Write PeerJS error handling that detects when a peer disconnects and automatically attempts to reconnect with exponential backoff.

Frequently asked questions

What is peerjs?

A JavaScript library that connects two browsers directly to each other for real-time data, audio, or video transfer, no server relay needed once the connection is established, using WebRTC built into modern browsers.

What language is peerjs written in?

Mainly TypeScript. The stack also includes TypeScript, JavaScript, WebRTC.

How hard is peerjs to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is peerjs for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.