Should'nt it be `exec(sprintf('sudo %s install %s -g', $npm, $recess), $output, $code);`

This said, you should check if npm is installed.