9

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 ?
  //Run the server:

 $> peerjs --port 9000 --key peerjs     
         or
 var PeerServer = require('peer').PeerServer;
 var server = new PeerServer({port: 9000, path: '/myapp'});

what's the difference between above steps. when and where to use those steps.

neophyte
  • 6,540
  • 2
  • 28
  • 43
John
  • 129
  • 2
  • 3
  • 12

4 Answers4

11

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

Socke
  • 111
  • 1
  • 3
  • 1
    are you done with this steps... how about the accepted answer? – gumuruh May 08 '20 at 15:18
  • 1
    It works. After running nodejs /root/node_modules/peer/node_modules/ws/index.js, open your browser and type http://127.0.0.1:443/peerjs. You should see this JSON file ({"name":"PeerJS Server","description":"A server side element to broker connections between PeerJS clients.","website":"http://peerjs.com/"}) – Tran Anh Minh Jun 20 '20 at 04:56
4

There are few ways to get peerjs-server:

  1. npm install peer

  2. git clone https://github.com/peers/peerjs-server

  3. 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.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
DanilaK
  • 51
  • 1
2

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: '/'})
Guilherme Kich
  • 321
  • 1
  • 5
  • 1
    where is it located server.js? – GENESIS Oct 06 '20 at 07:29
  • server.js is the js file that you have created and where you put the code to start your server node. Actually the server.js can have any name you want. It can be myserver.js for example. The name server.js is just to reming that it is the file that start the server – Guilherme Kich Jan 15 '21 at 00:37
-3

node peerjs --port 9000 --key peerjs

That worked for me on macOS.

peerjs or ./peerjs doesn't work on terminal.

S To
  • 73
  • 6