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?
The enoent meaning error no entry. This is used for more than files or dictionaries.
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.
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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With