Downloading Torrent with Node.JS

You can use node-torrent for this.

Then, to download a torrent:

var Client = require('node-torrent');
var client = new Client({logLevel: 'DEBUG'});
var torrent = client.addTorrent('a.torrent');

// when the torrent completes, move it's files to another area
torrent.on('complete', function() {
    console.log('complete!');
    torrent.files.forEach(function(file) {
        var newPath = '/new/path/' + file.path;
        fs.rename(file.path, newPath);
        // while still seeding need to make sure file.path points to the right place
        file.path = newPath;
    });
});

Alternatively, for more control, you can use transmission-dæmon and control it via its xml-rpc protocol. There's a node module called transmission that does the job! Exemple:

var Transmission = require('./')

var transmission = new Transmission({
    port : 9091,
    host : '127.0.0.1'
});

transmission.addUrl('my.torrent', {
    "download-dir" : "/home/torrents"
}, function(err, result) {
    if (err) {
        return console.log(err);
    }
    var id = result.id;
    console.log('Just added a new torrent.');
    console.log('Torrent ID: ' + id);
    getTorrent(id);
});