Forever-monitor throwing ENOENT and not working - node.js

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...

Related

NodeJs script with child_process spawn on Windows, why I need 'shell: true' for ENOENT error?

I'm using this code:
const {
spawn
} = require('child_process');
let info = spawn('npm', ["-v"]);
info.on('close', () => {
console.log('closed');
}
But I have this error:
events.js:182
throw er; // Unhandled 'error' event
^
Error: spawn npm ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:189:19)
at onErrorNT (internal/child_process.js:366:16)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
If I use instead:
let info = spawn('npm', ["-v"], {shell: true});
it works!
But why I need shell: true? I need also to see the stdout of that spawn, so I'm also using this:
let info = spawn('npm', ["-v"], {shell: true, stdio: 'inherit'});
It's correct?
While calling spawn itself, there is no npm command under spawn. Thus you got that error message. Instead of using spawn itself, while adding shell: true, spawn will use shell of your system to run that command. Since your system has npm, it works.
let info = spawn('npm', ["-v"], {shell: true, stdio: 'inherit'}); It's correct?
The code is fine if your parameters of spawn are controllable. But generally, I suggest use pure spawn without using shell. The risk will reduce without touching shell directly.
Since you need the stream return from spawn. I have checked other solution here. Without shell: true, You can use the code:
const {
spawn
} = require('child_process');
let projectPath = ''//the path of your project
let info = spawn('npm', ['-v'], { cwd: projectPath });
let result = '';
info.stdout.on('data', function(data) {
result += data.toString();
console.log(result);
}

Node.js ENOENT Reading PDF file

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.

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.

Resources