@mohdmahmodi/p2p-net
v1.1.2
Published
Zero-config P2P networking with end-to-end encryption. WebRTC + NaCl.
Maintainers
Readme
@mohdmahmodi/p2p-net
Zero-configuration P2P networking with E2E encryption. Direct connections between browsers and Node.js.
Install
npm install @mohdmahmodi/p2p-netQuick Start
import { createNode } from "@mohdmahmodi/p2p-net";
const node = createNode();
await node.start();
// Your ID is your public key
console.log("My ID:", node.id);
// Connect & send encrypted data
node.connectToPeer("peer-id");
node.send("peer-id", new TextEncoder().encode("Hello P2P!"));
// Receive data
node.onData((data, peerId) => {
console.log("Message:", new TextDecoder().decode(data));
});Features
- 🔐 End-to-end encryption (Ed25519/NaCl)
- 🌐 NAT traversal (WebRTC + relay fallback)
- ⚡ Zero configuration
- 📦 167KB bundle
- 🔧 TypeScript native
Documentation
Full documentation at p2p-net.dev →
Quick Examples
Browser
const node = createNode({
relayUrl: "wss://relay.example.com",
});File Transfer
const file = await fileInput.files[0].arrayBuffer();
node.send(peerId, new Uint8Array(file));React Hook
function useP2P() {
const [node, setNode] = useState(null);
useEffect(() => {
const p2p = createNode();
p2p.start().then(() => setNode(p2p));
return () => p2p.stop();
}, []);
return node;
}Relay Server
npx @mohdmahmodi/p2p-net-relayLicense
MIT
