Unable to upload .torrent with node.js and utorrent-api - node.js

I'm trying to use utorrent-api library for node.js as in example:
request({'uri' : 'http://releases.ubuntu.com/13.04/ubuntu-13.04-desktop-i386.iso.torrent', 'encoding': null}, function (error, response, torrentFileBuffer) {
utorrent.call('add-file', {'torrent_file': torrentFileBuffer}, function(err, data) {
if(err) { console.log('error : '); console.log(err); return; }
console.log('Successfully added torrent file !');
console.log(data);
});
});
and I'm getting this error in console:
error :
{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
I can connect to uTorrent with:
utorrent.call('list', function(err, torrents_list) {
console.log(torrents_list);
});
And I'm getting torrents list correctly.
I tried to save .torrent file to disk and it looks ok, so the problem is with file upload.
uTorrent 3.3 is running on Linux. WebUI is working and I can upload .torrent files through browser.
How can I debug this error?

Related

fs.writeFile not saving even when path is correct

Having an issue with fs.writeFile in my nodejs app running locally where im getting an error of this below,
I am running on localhost xampp also on windows if that may be an issue?
[Error: ENOENT: no such file or directory, open 'C:\Users\exampleuser\Desktop\examplenodejspath\product\sku123.json'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Users\\exampleuser\\Desktop\\examplenodejspath\\product\\sku123.json'
}
Below is a copy of the code.
var product = {"SKU": "sku123","name": "test"};
fs.writeFile(__dirname + "/product/" + product.SKU + ".json", product, 'utf8', function (err) {
if (err) {
return console.log(err);
}
console.log("product was saved!");
});
I can confirm the path is correct. but for some reason it still returns its not correct.
Any help would be appericated

Cannot write on json file in express app nodejs

I'm trying to read and write some data in express application (in a json file which already exists and has some data) using FS nodejs module but it returns this error in console:
Object { errno: -13, code: "EACCES", syscall: "open", path: "data.json" }
It works in localhost, but not on my web server and I don't understand where is the problem.
I've tried several ways to write on file and I'm sure this one works perfectly.
SERVER SIDE CODE:
app.post('/addLocation', function(req, res){
var jsonFile = JSON.parse(fileSystem.readFileSync(path.join(__dirname,'data.json'),'utf8'));
jsonFile.locations.push(req.body); //json data is an array named 'locations'
fileSystem.writeFile('data.json', JSON.stringify(jsonFile, null, 2), function(err){
if (err) res.send(err);
else res.send('SERVER MESSAGE: data saved');
});
})
CLIENT SIDE CODE:
const data = {name, address, lat, lng, content, audience, detail, language, purpose, description};
$.ajax({
url: '/addLocation',
type: "POST",
data: data,
success: function(result){
console.log(result);
}
});
ERROR in console:
Object { errno: -13, code: "EACCES", syscall: "open", path: "data.json" }

NodeJS File System sudden UNKNOWN error

Few days ago, fs.watch() was still able to work with my path ////networkFolder. But after I restarted the server (hard reset), it gave me an unknown error.
Now for me to check the path I did some troubleshooting, so I used fs.open()
fs.open('\\\\networkFolder\\sharedFolder\\p\\a\\t\\h', 'r', (err, fd) => {
if(err) throw err;
fs.close(fd, (err) => {
if (err) throw err;
});
});
but it gave me an error.
Error: UNKNOWN: unknown error, open '\\networkFolder\sharedFolder\p\a\t\h'
Then I used fs.stat() to verify:
fs.stat('\\\\networkFolder\\sharedFolder\\p\\a\\t\\h', function(err, stat){
if(err){
console.log(err);
} else {
console.log(stat);
}
});
then the result was:
{ Error: UNKNOWN: unknown error, stat '\\networkFolder\sharedFolder\p\a\t\h'
errno: -4094,
code: 'UNKNOWN',
syscall: 'stat',
path: '\\\\networkFolder\\sharedFolder\\p\\a\\t\\h' }
From what I remember, I've used net use to setup my network folder but I don't know if that actually help/works in my problem. I did it again but still no luck for me
Please let me know your thoughts regarding the issue.
Thank you!
I was having a similar issue and figured out that the user account running the node script (Local System in my case) didn't have access to the shared network path. Try running the script as a user that has access to the network share

Error downloading file from my Node.js server

I'm trying to make a download link on my server for a zip file and I'm currently getting this error: (Note, still just testing it on local machine)
{ [Error: ENOENT: no such file or directory, stat 'C:\Users\Jordan\Desktop\Websites\HappyCamel\Users\Jordan\Desktop\Websites\HappyCamel']
errno: -4058,
code: 'ENOENT',
syscall: 'stat',
path: 'C:\\Users\\Jordan\\Desktop\\Websites\\HappyCamel\\Users\\Jordan\\Desktop\\Websites\\HappyCamel',
expose: false,
statusCode: 404,
status: 404 }
The relevant code is this:
router.get('/file/:name', function(req, res, next) {
console.log('test123'); //successfully prints to console
res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
console.log('test456'); //successfully prints to console
if(err) {
console.log(err) //I'm assuming this is source of logged error
} else {
console.log("no error"); //doesn't print
}
});
})
edit:
Fixed it with changing this line:
res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
to
res.download('./test123.zip', 'test123.zip', function(err) {
but now I get
angular.min.js:114 ReferenceError: success is not defined
error on my browser, but no errors in my node console (my "no error" line is printing)
you are using relative path. when you do this:
res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
it will look for Users/Jordan/Desktop/Websites/HappyCamel/ inside your current file's directory. looks like what you need is full path, or better a correct relative path- from the error it looks like the file is located with your code, so this should do:
res.download('./', 'test123.zip', function(err) {

Webshot fails on Meteor in DigitalOcean Ubuntu 14.04

I am using this code to generate pdf:
let fileUri = process.env.PWD + '/storage/orders-pdf/' + fileName;
// Commence Webshot
webshot(html_string, fileUri, options, function(error) {
fs.readFile(fileUri, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileUri);
fut.return(data);
});
});
let pdfData = fut.wait();
But it throws the following error:
{ [Error: ENOENT, open '/opt/holi/storage/orders-pdf/Attributes.pdf']
errno: 34,
code: 'ENOENT',
path: '/opt/holi/storage/orders-pdf/Attributes.pdf' }
Tried to use npm package https://github.com/brenden/node-webshot
Then code works perfectly on localhost, but fails on the server and throws this error:
EDIT:
Even when running webshot without:
fs.readFile(fileUri, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileUri);
fut.return(data);
});
The file is not created..
EDIT-2:
Webshot throws an error: [Error: PhantomJS exited with return value 2]
EDIT-3:
Actual issue: https://github.com/brenden/node-webshot/issues/123
I had a similar problem, and spent most of the day trying to figure out the issue. I ended up adding:
"phantomPath": "/usr/bin/phantomjs"
to my webshot options object. The phantom path I used is where mup installs phantomjs on your server setup.

Resources