Search code examples
javascriptnode.jsgraphicsmagick

Node.js: Error: spawn ENOENT while using GM module


Even though this has been asked several times, none of the existing answers helped me out. Using a MEAN environment (on Mac OSX), I installed graphicsmagick using:

sudo npm install gm

Whenever I run the following script, I get this error:

{ [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }

This is the piece of code I am trying to run:

var gm = require('gm');    
//var gm = require('gm').subClass({ imageMagick: true }); //tried this one too 

    gm('./project/public/images/webshots/test1.jpg')
           .resize(320, 240)
           .write('./project/public/images/webshots/test2.jpg', function (err) {
        if (!err) console.log('done');
        if(err){
           console.log(err);   
        }
        });

Appropriate writing permissions were given by:

sudo chmod -R 777 ./project/public/images/webshots

I even tried several source/destination path combinations. What else could I have missed?


Solution

  • The gm module can't find the path to the gm executable. So it sounds like your $PATH needs to be updated to include the path where graphicsmagick was installed to.