Я пытаюсь выполнить эту функцию, но в терминале с Node.JS
var WebTorrent = require('webtorrent')
var client = new WebTorrent()
var magnetURI = 'magnet: ...'
client.add(magnetURI, { path: '/path/to/folder' }, function (torrent) {
torrent.on('done', function () {
console.log('torrent download finished')
})
})
Я имею в виду, например, создать тег <button>
, а при нажатии - предыдущая функциявыполняться в консоли nodejs, а не в консоли браузера.
ДОПОЛНИТЕЛЬНО: я выполняю эти два файла:
app.js
let http = require('http');
let fs = require('fs');
let handleRequest = (request, response) => {
response.writeHead(200, {
'Content-Type': 'text/html'
});
fs.readFile('./index.html', null, function (error, data) {
if (error) {
response.writeHead(404);
respone.write('Whoops! File not found!');
} else {
response.write(data);
}
response.end();
});
};
http.createServer(handleRequest).listen(8000);
И
index.html, который содержит тег <button>
, но ничего не делает.