I'm trying to configure Spatie/Browsershot for a project, written in Laravel but after completing all of the steps, I still get one error:
'node' is not recognized as an internal or external command, operable program or batch file
A have installed the latest versions of node and npm and the both of them exist in the PATH and work on cmd as well.
Like it's written in the official documentation on GitHub, I've ran:
- npm install puppeteer
- composer require spatie/browsershot
In the code I've written:
use Spatie\Browsershot\Browsershot;
//Method to generate some random id
$unique_id = uniqid('img_');
//The path to the node and npm folders
$path_node = realpath('C:\\"Program Files"\\nodejs');
$path_npm = realpath('C:\\Users\\Hristo\\AppData\\Roaming\\npm');
//The $content is actually a stored HTML code
Browsershot::html("$content")->setScreenshotType('jpeg', 100)
->setNodeBinary($path_node)
->setNpmBinary($path_npm)
->save("$unique_id.jpeg");
Program Files is with double quotation marks, otherwise Laravel throws me an error because of the white space in between the two words.
I'm not sure about the paths, are they correctly written? (the problem with the backslashes in windows)
->setXyzBinary()
take the executables name, rather than just the directory? – mario$node_path = '"C:\Program Files\nodejs\node.exe"';
? (and the same for npm) – Travis BritzXyz
to represetsetNodeBinary()
andsetNpmBinary()
– Travis Britz