Reputation: 6559
I am new in Node.js platform and want to use https://www.npmjs.com/package/simple-peer module in my application. But can not figure out how to implement that in my application. I can't figure out their documentation. Is there any resource that can show the procedure of using that module with Node.js or Node+Express?
Upvotes: 3
Views: 3614
Reputation: 2263
Might be late but :
If you do not want to, it's not compulsory to use browserify
or webpack
for this very module to work, but is a good practice though, atleast for now.
In simple-peer package it is mentioned :
Note: If you're NOT using browserify, then use the included standalone file simplepeer.min.js. This exports a SimplePeer constructor on window.
This means you can get SimplePeer()
on the window
object by adding a script
tag in your html
file like :
<script src="<path to your node_modules>/simple-peer/simplepeer.min.js"></script>
For me this works :
<script src="<path to your node_modules>/simple-peer/simplepeer.min.js"></script>
<script src="/index.js"></script> <!-- Keep this script tag below simplepeer.min.js-->
Now use SimplePeer()
inside index.html
as :
const peer = new SimplePeer({
// Code ...
});
Hope this helps :)
Upvotes: 5
Reputation: 29814
As explained in the documentation,
This module works in the browser with browserify.
Basically you need to write nodeJS
(i.e. commonJS) code - as shown in the examples - then using browserify, generate a bundle file which can be used browser side.
Most likely, webpack can be used as an alternative to browserify
Upvotes: 3