Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instructions for noobies #1277

Closed
Luc45 opened this issue Jan 29, 2018 · 3 comments
Closed

Instructions for noobies #1277

Luc45 opened this issue Jan 29, 2018 · 3 comments

Comments

@Luc45
Copy link

@Luc45 Luc45 commented Jan 29, 2018

Hello!

I'm not very into NPM and I'm trying to use this package...

While following the install instructions presented on README.md, I ran:

npm install webtorrent

On a fresh folder. After running this command, I have a folder and a file: node_modules and package.lock.json

How do I get to the point where I can apply the example usage in the browser as showed in the README.md?

var WebTorrent = require('webtorrent')

var client = new WebTorrent()
var magnetURI = '...'

client.add(magnetURI, function (torrent) {
  // Got torrent metadata!
  console.log('Client is downloading:', torrent.infoHash)

  torrent.files.forEach(function (file) {
    // Display the file by appending it to the DOM. Supports video, audio, images, and
    // more. Specify a container element (CSS selector or reference to DOM node).
    file.appendTo('body')
  })
})

Edit: I've managed to call webtorrent.min.js on a HTML file, but when I try to run the snippet above it says require() is not defined.

Edit 2: Allright, moved all content from index.html to a test.js file with the contents above, now when I ran node test.js it just died out of memory.

@Yhozen

This comment has been minimized.

Copy link

@Yhozen Yhozen commented Feb 4, 2018

Node and browser are two different environment. If you want to run that snippet in browser change var WebTorrent = require('webtorrent') to const { WebTorrent } = window because what webtorrent.min.js is doing is making the webtorrent constructor available in the window object. If you still want to use require you will need to use something like webpack or browserify because require is not available in browser

@gauravsaini

This comment has been minimized.

Copy link

@gauravsaini gauravsaini commented Feb 4, 2018

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Feb 16, 2018

@Yhozen's explanation is correct. Thanks for helping out @Luc45 :)

@feross feross closed this Feb 16, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.