I got the following code from the git-hub but I don\'t know how to use and execute.
$> npm install peer --->where i want to install this node_module
you can run :
npm install peer
Then your server.js you add: `
//Peer server
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
const { PeerServer } = require('peer');
const peerServer = PeerServer({ port: 443,
path: '/' ,
ssl: {
key: privateKey,
cert: certificate
}
});
` Make sure that on client side (script run on index.html) you have:
myPeer = new Peer({host:'/',
secure:true,
port:443,
path: '/'})
node peerjs --port 9000 --key peerjs
That worked for me on macOS.
peerjs or ./peerjs doesn't work on terminal.
After npm install peer
go to /root/node_modules/peer/node_modules/ws
. Then add something like
var PeerServer = require('peer').PeerServer;
var server = PeerServer({port: 443, path: '/peerjs'});
in index.js
and start the server with nodejs /root/node_modules/peer/node_modules/ws/index.js
There are few ways to get peerjs-server:
npm install peer
git clone https://github.com/peers/peerjs-server
download and unpack zip-file from git
After that go to <path_to_peerjs-server>/bin
and run peerjs-server with command:
node peerjs --port 9000 --key peerjs
or
./peerjs --port 9000 --key peerjs
peerjs-server has more options, and you can see them with command ./peerjs
without arguments.