Make a P2P connection in 10 minutes

Carlos Galarza
2 min readFeb 13, 2018

--

This is a short guide on how to make a P2P chat. My aim is to give you only a taste if you like I could write a deeper article explaining how all these things work. That said, let's start.

Preparation

The only thing you will need is the latest NodeJS and your favorite editor, mine is Visual Studio Code. Now create a folder for our project, open a command line, initialize an NPM repo with npm init and install some libraries we will need with:

npm i --save discovery-swarm dat-swarm-defaults portfinder get-port

I will explain what these libraries do later.

Our first P2P connection

Let's start by doing a simple P2P connection, thanks to some great libraries from the Node.js community it is too simple:

Run this code in two consoles and this is it!. Now you can run it in other devices right in your LAN and should work even without internet, also you can share and run this script in any other computer with internet, it just works, so nice!

What’s is next?

We will build a P2P chat for our long term project using this code. The chat will have end-to-end encryption and can verify messages.

Make a P2P chat in 10 minutes (Soon …)

I love feedback, ask me questions, comment on your experience with P2P technologies and share your ideas!

This series is possible thanks to the awesome tools delivered by the DatProject, Webtorrent and the NodeJS community.

This article is part of a medium-term project you can find here:

Create a P2P Real-Time Game App

If you have any questions, please ask them in the comments, I would love to help!

If you are having process problems, facing hard technical decisions, or struggling with hard tech stuff, I offer tailored help for companies as a Fractional CTO or consultant. DM me on Twitter if you are interested, or follow me, I usually publish interesting tech/software/maker stuff.

--

--

Carlos Galarza

Founder at codeportal.io. I love programming languages, machines, and tech! 👨🏽‍💻