Node.js ENOENT Reading PDF file - node.js

I need to read pdf file and I use pdf-text-extract. It works perfectly on my localhost. But when I tried to run the program on server, I got the following error
spawn called
{ '0': 'pdftotext',
'1':
[ '-layout',
'-enc',
'UTF-8',
'/tmp/the_file_name.pdf',
'-' ],
'2': { encoding: 'UTF-8', layout: 'layout', splitPages: true } }
events.js:72
throw er; // Unhandled 'error' event
Error: spawn ENOENT
at errnoException (child_process.js:1011:11)
at Process.ChildProcess._handle.onexit (child_process.js:802:34)
Here is how I use pdf-text-extract
var extract = require('pdf-text-extract');
.....
.then (function () {
console.log(fs.readdirSync('/tmp'));
var extractAsync = Promise.promisify(extract);
return extractAsync(filePath);
})
.catch (function (err) {
console.log(err);
});
As you can see, I have added catch, but why the error is Unhandled 'error' event.
I have also checked that the file is exist using fs.readdirSync. What cause the error and how can I fix it?

Your server does not have the pdftotext command, which the pdf-text-extract module tries to spawn as a child process. The readme for the module includes a link to how to install the program for various platforms.

Related

node-watch ECONNRESET on network drive

I have a small app that uses node-watch to watch 2 network drives and moves files between them when a change occurs. But the network often goes down, how do I prevent ECONNRESET crashes?
The code:
watch(directories.SQL_XML_IN, {
recursive: false,
filter: function (name) {
return /\.xml$/i.test(name);
}
}, function (evt, name) {
if (evt == 'update') {
// move files
}
});
And the error:
events.js:141
throw er; // Unhandled 'error' event
^
Error: watch null ECONNRESET
at exports._errnoException (util.js:870:11)
at FSEvent.FSWatcher._handle.onchange (fs.js:1217:21)
Try something like this:
var watcher = watch('...');
watcher.on('error', function(err) {
// handle errors
// close it if necessary
watcher.close()
});

Node js + imagemagick + Error: spawn ENOENT

Hi am trying to implement Imagemagick package using node.js
I added my following code.
var im = require('imagemagick');
router.post('/conversation/start', function(req, res) {
var args = ["/public/images/team/rajini.jpg", "-crop", "120x80+30+15", "output.png"];
im.convert(args, function(err) {
if (err) {
throw err;
}
res.end("Image crop complete");
});
});
But i getting the following error in terminal.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:988:11)
at Process.ChildProcess._handle.onexit (child_process.js:779:34)
npm ERR! weird error 8
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

resize picture with nodeJs imageMagick

I would like to resize some picture before send to user in nodeJs with express
im = require("imagemagick")
app.get('/image/:dossier/:id/:taille', function (req, res) {
var image = __dirname + '/public/img/bibliotheque/'+req.params.dossier+'/'+req.params.id+'.jpg';
im.resize({
srcPath : image,
width : req.params.taille
},
function(err, stdout, stderr) {
if (err){
log.error(err);
} else {
res.contentType("image/jpeg");
res.end(stdout);
}
});
});
but it's return :
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
I try to launch my app with and without sudo but no change
I'm on OSX
Please, help me
You need to install the application in addition to the npm module.
brew install imagemagick

spawning a child process to call npm-installed command in nodejs causes ENOENT in windows

I've searched a lot but got no correct answer.
Firstly I'm sure the command is usable under command line, here is the output:
> lessc
lessc: no input files
usage: lessc [option option=parameter ...] <source> [destination]
However when use child_process.spawn, I got:
> node test.js
Encountered error: { [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }
I'm sure the process.env is given to spawn, here is the nodejs code:
var build = require('child_process').spawn(
'lessc',
[],
{
stdio: 'inherit',
env: process.env
}
);
build.on(
'error',
function (err) {
console.log('Encountered error:', err);
process.exit();
}
);
build.on(
'close',
function (err) {
console.log('close');
}
);
And weiredly, it only encounter ENOENT when the command is installed via npm install -g, it works well on for example dir or del system command
As is turns out, the following works:
var spawn = require('child_process').spawn;
var b = spawn(
process.env.comspec,
['/c', 'lessc'],
{ stdio: 'inherit' }
);
Note that you don't need to explicitly pass env as you do, the default is to inherit.

Forever-monitor throwing ENOENT and not working

so I have:
var forever = require('forever-monitor');
var Monitor = forever.Monitor;
var child = new Monitor('clusters.js', {
max: 10,
silent: false,
killTree: true,
logFile: './logs/forever.log',
outFile: './logs/app.log',
errFile: './logs/error.log'
});
child.on('exit', function (err) {
console.log('Server exitted');
});
child.start();
and it always throw the same error: events.js:72 throw er; // Unhandled 'error' event with:
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
npm ERR! weird error 8
npm ERR! not ok code 0
Does anyone know what is going on and how to fix it?
Im on Windows 7 with:
"express": "3.3.5",
"forever-monitor": "~1.2.2"
https://github.com/blai/grunt-express/issues/12
Apparently the problem is with forever-monitor 1.2, I downgraded to 1.1 and it just worked.
From what I got there they dont seem to be doing anything about it either...

Resources