spawn ENOENT error with NodeJS - node.js

I get an error using GM() on my remote server, I think i get an issue when I try to write the file... It works perfectly on my local server...
My code :
gm()
.in('-page', '+0+0')
.in('/var/www/myapp/public/images/instabox.jpg')
.in('-page', '+10+10')
.in(image)
.mosaic()
.minify()
.write(newFileName, function (err) { // newfilename = '/var/www/myapp/public/uploads/mydir/image.jpg'
if (!err) console.log('done');
if (err) console.log(err);
callback();
});
My error :
{ [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }
Response of the issue:
I put back GM on my remote server and it was the issue, GM was not
well installed...

Related

Unable to unlink webp image in nodejs. Having error resource busy or locked

I am making img converter (png,webp,jpg,etc)
using multer to uplaod image and sharp to convert img
very thing is going fine but when I unlink uploaded webp img an error shows up!
ERROR
Error: EBUSY: resource busy or locked, unlink 'public\uploads\Windows 101632682048612-.webp' at Object.unlinkSync (fs.js:1251:3) at Object.<anonymous> (D:\nodejs\webp\index.js:81:14) { errno: -4082, syscall: 'unlink', code: 'EBUSY', path: 'public\\uploads\\Windows 101632682048612-.webp' }
let outputFilePath = "public/converted/"+file.originalname.split('.').slice(0, -1).join('.') + "--converted." + format;
let path= sharp(file.path)
.toFile(outputFilePath, (err, info) => {
if (err) throw err;
// code to unlink file
try{
fs.unlinkSync(file.path)
}
catch(err){
console.log(err)
}
})
return path.options.fileOut;
}```

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

How to run exe file from node.js script?

I have an exe and I want to run it from node.js, and pass an argument, except that it doesn't work..
var exec = require('child_process').execFile;
const fs = require('fs');
try {
if (fs.existsSync("./program/bin/Release/program.exe")) {
console.log("Exists")
} else {
console.log("Not Exists")
}
} catch(err) {
console.log(err)
}
setTimeout(function() {
exec('./program/bin/Release/program.exe manual', function(err, data) {
console.log(err)
console.log(data.toString());
});
}, 0);
It definitely exists as it prints exists, and I can run it from a cmd prompt giving manual as an argument. But through node.js it is not working. It comes back with
Error: spawn ./program/bin/Release/program.exe manual ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn ./program/bin/Release/program.exe manual',
path: './program/bin/Release/program.exe manual',
spawnargs: [],
cmd: './program/bin/Release/program.exe manual'
}
Does anyone know?
Thanks
Arguments should be passed as an array of strings as the second argument, like so:
exec('./program/bin/Release/program.exe', ['manual'], function(err, data) {
console.log(err)
console.log(data.toString());
});
https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

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.

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

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?

Resources