Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js Error: spawn ENOENT

I am trying to convert SVG to PNG with node js. My code is here:

http.createServer(function (req, res) {   res.writeHead(200, {'Content-Type': 'image/png'});   var convert = child_proc.spawn("convert", ["svg:", "png:-"]),       values = (url.parse(req.url, true).query['values'] || ".5,.5")         .split(",")         .map(function(v){return parseFloat(v)});    convert.stdout.on('data', function (data) {     res.write(data);   });   convert.on('exit', function(code) {     res.end();   });    jsdom.env({features:{QuerySelector:true}, html:htmlStub, scripts:scripts, done:function(errors, window) {     var svgsrc = window.insertPie("#pie", w, h, values).innerHTML;     //jsdom's domToHTML will lowercase element names     svgsrc = svgsrc.replace(/radialgradient/g,'radialGradient');     convert.stdin.write(svgsrc);     convert.stdin.end();   }}); }).listen(8888); 

While executing I got this error (in MAC)

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 have specified the path for nodejs. But i dont know why it fails. Any idea about this issue?

like image 889
sprabhakaran Avatar asked Sep 17 '13 10:09

sprabhakaran


People also ask

What is Enoent error?

The enoent meaning error no entry. This is used for more than files or dictionaries.

What is spawn node JS?

spawn() : The spawn function launches a command in a new process and you can use it to pass that command any arguments. It's the most generic spawning function and all other functions are built over it [docs]. child_process. execFile() : The execFile function is similar to child_process.


2 Answers

It's likely failing because it can't find the convert application. Does the path to convert exist in your environment PATH? Can you run convert from your terminal?

like image 179
badsyntax Avatar answered Sep 22 '22 21:09

badsyntax


I was getting the error

Uncaught Error: spawn myExeCommand ENOENT 

Once I added 'options' to the spawn(), it worked.

let options = {shell: true}; let theProcess = child_process.spawn(myExeCommand, null, options); 
like image 40
Sagan Avatar answered Sep 21 '22 21:09

Sagan