Latest commit 587e06a Sep 29, 2017 @DiegoRBaquero DiegoRBaquero Merge pull request #18 from webtorrent/greenkeeper/initial
Add Greenkeeper badge 🌴
Failed to load latest commit information.
test standard Mar 2, 2017
.travis.yml travis: test latest node Dec 2, 2015
.zuul.yml sauce labs: add back ios Apr 22, 2017
LICENSE feross -> webtorrent Apr 14, 2017 Update Sep 29, 2017
index.js use safe-buffer Apr 22, 2017
package.json 5.1.7 Apr 22, 2017

magnet-uri travis npm downloads javascript style guide Greenkeeper badge

Parse a magnet URI and return an object of keys/values.

Sauce Test Status

Also works in the browser with browserify! This module is used by WebTorrent.


npm install magnet-uri



Parse a magnet URI and return an object of keys/values.

var magnet = require('magnet-uri')

// "Leaves of Grass" by Walt Whitman
var uri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&'

var parsed = magnet.decode(uri)
console.log(parsed.dn) // "Leaves of Grass by Walt Whitman.epub"
console.log(parsed.infoHash) // "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36"

The parsed magnet link object looks like this:

    "xt": "urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
    "dn": "Leaves of Grass by Walt Whitman.epub",
    "tr": [

    // added for convenience:
    "infoHash": "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
    "infoHashBuffer": ...,
    "name": "Leaves of Grass by Walt Whitman.epub",
    "announce": [


Convert an object of key/values into a magnet URI string.

var magnet = require('magnet-uri')

var uri = magnet.encode({
  xt: [
  xl: '10826029',
  dn: 'mediawiki-1.15.1.tar.gz',
  tr: [
  as: '',
  xs: [

console.log(uri) // the magnet uri

The returned magnet uri will be:


You can also use convenience key names like name (dn), infoHash (xt), infoHashBuffer (xt), announce (tr), and keywords (kt).


MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.