Monday, 15 May 2017

How to use a package for node in angular 2

I am doing a school project to teach us the basics of a bittorrent client. I decided to use node-torrent found here https://www.npmjs.com/package/node-torrent to help me. It is made for node, I am using angular 2.

I want to know if it is possible to implement this in an angular 2 web application and if not, how I would otherwise use it. I am pretty new to angular. I have attempted to just follow the tutorial which has us using this bit of code:

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;
    });
});

But the problem is I have no idea where to implement this. Also, usually there is a way to add this to my package.json in angular 2 with a npm install, but there is no indication of how to do that. I am assuming I have to download it?



via questions

No comments:

Post a Comment