Gathering detailed insights and metrics for peer
Gathering detailed insights and metrics for peer
Gathering detailed insights and metrics for peer
Gathering detailed insights and metrics for peer
npm install peer
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (91.82%)
JavaScript (7.09%)
Dockerfile (1.1%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4,575 Stars
946 Commits
1,115 Forks
137 Watchers
21 Branches
43 Contributors
Updated on Jul 14, 2025
Latest Version
1.0.2
Package Id
peer@1.0.2
Unpacked Size
197.99 kB
Size
49.44 kB
File Count
11
NPM Version
10.2.4
Node Version
20.10.0
Published on
Dec 05, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
7
24
PeerServer helps establishing connections between PeerJS clients. Data is not proxied through the server.
Run your own server on Gitpod!
If you don't want to develop anything, just enter few commands below.
Install the package globally:
1$ npm install peer -g
Run the server:
1$ peerjs --port 9000 --key peerjs --path /myapp 2 3 Started PeerServer on ::, port: 9000, path: /myapp (v. 0.3.2)
Check it: http://127.0.0.1:9000/myapp It should returns JSON with name, description and website fields.
Also, you can use Docker image to run a new container:
1$ docker run -p 9000:9000 -d peerjs/peerjs-server
1$ kubectl run peerjs-server --image=peerjs/peerjs-server --port 9000 --expose -- --port 9000 --path /myapp
If you have your own server, you can attach PeerServer.
Install the package:
1# $ cd your-project-path 2 3# with npm 4$ npm install peer 5 6# with yarn 7$ yarn add peer
Use PeerServer object to create a new server:
1const { PeerServer } = require("peer"); 2 3const peerServer = PeerServer({ port: 9000, path: "/myapp" });
Check it: http://127.0.0.1:9000/myapp It should returns JSON with name, description and website fields.
1<script> 2 const peer = new Peer("someid", { 3 host: "localhost", 4 port: 9000, 5 path: "/myapp", 6 }); 7</script>
You can provide config object to PeerServer
function or specify options for peerjs
CLI.
CLI option | JS option | Description | Required | Default |
---|---|---|---|---|
--port, -p | port | Port to listen (number) | Yes | |
--key, -k | key | Connection key (string). Client must provide it to call API methods | No | "peerjs" |
--path | path | Path (string). The server responds for requests to the root URL + path. E.g. Set the path to /myapp and run server on 9000 port via peerjs --port 9000 --path /myapp Then open http://127.0.0.1:9000/myapp - you should see a JSON reponse. | No | "/" |
--proxied | proxied | Set true if PeerServer stays behind a reverse proxy (boolean) | No | false |
--expire_timeout, -t | expire_timeout | The amount of time after which a message sent will expire, the sender will then receive a EXPIRE message (milliseconds). | No | 5000 |
--alive_timeout | alive_timeout | Timeout for broken connection (milliseconds). If the server doesn't receive any data from client (includes pong messages), the client's connection will be destroyed. | No | 60000 |
--concurrent_limit, -c | concurrent_limit | Maximum number of clients' connections to WebSocket server (number) | No | 5000 |
--sslkey | sslkey | Path to SSL key (string) | No | |
--sslcert | sslcert | Path to SSL certificate (string) | No | |
--allow_discovery | allow_discovery | Allow to use GET /peers http API method to get an array of ids of all connected clients (boolean) | No | |
--cors | corsOptions | The CORS origins that can access this server | ||
generateClientId | A function which generate random client IDs when calling /id API method (() => string ) | No | uuid/v4 |
Simply pass in PEM-encoded certificate and key.
1const fs = require("fs"); 2const { PeerServer } = require("peer"); 3 4const peerServer = PeerServer({ 5 port: 9000, 6 ssl: { 7 key: fs.readFileSync("/path/to/your/ssl/key/here.key"), 8 cert: fs.readFileSync("/path/to/your/ssl/certificate/here.crt"), 9 }, 10});
You can also pass any other SSL options accepted by https.createServer, such as `SNICallback:
1const fs = require("fs"); 2const { PeerServer } = require("peer"); 3 4const peerServer = PeerServer({ 5 port: 9000, 6 ssl: { 7 SNICallback: (servername, cb) => { 8 // your code here .... 9 }, 10 }, 11});
Make sure to set the proxied
option, otherwise IP based limiting will fail.
The option is passed verbatim to the
expressjs trust proxy
setting
if it is truthy.
1const { PeerServer } = require("peer"); 2 3const peerServer = PeerServer({ 4 port: 9000, 5 path: "/myapp", 6 proxied: true, 7});
By default, PeerServer uses uuid/v4
npm package to generate random client IDs.
You can set generateClientId
option in config to specify a custom function to generate client IDs.
1const { PeerServer } = require("peer"); 2 3const customGenerationFunction = () => 4 (Math.random().toString(36) + "0000000000000000000").substr(2, 16); 5 6const peerServer = PeerServer({ 7 port: 9000, 8 path: "/myapp", 9 generateClientId: customGenerationFunction, 10});
Open http://127.0.0.1:9000/myapp/peerjs/id to see a new random id.
1const express = require("express"); 2const { ExpressPeerServer } = require("peer"); 3 4const app = express(); 5 6app.get("/", (req, res, next) => res.send("Hello world!")); 7 8// ======= 9 10const server = app.listen(9000); 11 12const peerServer = ExpressPeerServer(server, { 13 path: "/myapp", 14}); 15 16app.use("/peerjs", peerServer); 17 18// == OR == 19 20const http = require("http"); 21 22const server = http.createServer(app); 23const peerServer = ExpressPeerServer(server, { 24 debug: true, 25 path: "/myapp", 26}); 27 28app.use("/peerjs", peerServer); 29 30server.listen(9000); 31 32// ========
Open the browser and check http://127.0.0.1:9000/peerjs/myapp
The 'connection'
event is emitted when a peer connects to the server.
1peerServer.on('connection', (client) => { ... });
The 'disconnect'
event is emitted when a peer disconnects from the server or
when the peer can no longer be reached.
1peerServer.on('disconnect', (client) => { ... });
Read /src/api/README.md
1$ npm test
We have 'ready to use' images on docker hub: https://hub.docker.com/r/peerjs/peerjs-server
To run the latest image:
1$ docker run -p 9000:9000 -d peerjs/peerjs-server
You can build a new image simply by calling:
1$ docker build -t myimage https://github.com/peers/peerjs-server.git
To run the image execute this:
1$ docker run -p 9000:9000 -d myimage
This will start a peerjs server on port 9000 exposed on port 9000 with key peerjs
on path /myapp
.
Open your browser with http://localhost:9000/myapp It should returns JSON with name, description and website fields. http://localhost:9000/myapp/peerjs/id - should returns a random string (random client id)
Google App Engine will create an HTTPS certificate for you automatically, making this by far the easiest way to deploy PeerJS in the Google Cloud Platform.
package.json
file for GAE to read:1echo "{}" > package.json 2npm install express@latest peer@latest
app.yaml
file to configure the GAE application.1runtime: nodejs 2 3# Flex environment required for WebSocket support, which is required for PeerJS. 4env: flex 5 6# Limit resources to one instance, one CPU, very little memory or disk. 7manual_scaling: 8 instances: 1 9resources: 10 cpu: 1 11 memory_gb: 0.5 12 disk_size_gb: 0.5
server.js
(which node will run by default for the start
script):1const express = require("express"); 2const { ExpressPeerServer } = require("peer"); 3const app = express(); 4 5app.enable("trust proxy"); 6 7const PORT = process.env.PORT || 9000; 8const server = app.listen(PORT, () => { 9 console.log(`App listening on port ${PORT}`); 10 console.log("Press Ctrl+C to quit."); 11}); 12 13const peerServer = ExpressPeerServer(server, { 14 path: "/", 15}); 16 17app.use("/", peerServer); 18 19module.exports = app;
gcloud
), replacing YOUR-PROJECT-ID-HERE
with your particular project ID:1gcloud app deploy --project=YOUR-PROJECT-ID-HERE --promote --quiet app.yaml
See PRIVACY.md
Discuss PeerJS on our Telegram chat: https://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og
Please post any bugs as a Github issue.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Moresimple-peer
Simple one-to-one WebRTC video/voice and data channels
@libp2p/peer-id
Implementation of @libp2p/interface-peer-id
peer-id
IPFS Peer Id implementation in Node.js
rollup-plugin-peer-deps-external
Rollup plugin to automatically add a library's peerDependencies to its bundle's external config.