Here are the steps to install node and npm on WHM server and cpanel.
Go to your WHM and then to EasyApache 4, there click on "Customize" in Currently Installed Packages and then make sure to enable nodejs16 (screenshot above)
When the installation is done, try to check does node works:
node -v
v16.20.0 // this should be response
Now try to check npm
npm -v
8.19.4 // you should get this answer
If npm command does not work, you should open .bashrc (located in root directory) and add this line:
export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH
to do that, type nano .bashrc go to the end of the file and paste:
.export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH
after that, your npm should work fine
If you are using this for puppeteer, then you can continue installing it:
npm install puppeteer@latest
if you want to use it with chromium-browser, here is how to install it on whm:
yum install chromium -y
to get the location where it is installed:
which chromium-browser
// output /bin/chromium-browser
And if by some weird coincidence, you are needing all of this to use Browsershot, here is how to use it. You will have to send chrome location, node location, npm location and also node modules location - like this:
Browsershot::html($htmlCode)
->setNodeBinary('/opt/cpanel/ea-nodejs16/bin/node')
->setNpmBinary('/opt/cpanel/ea-nodejs16/bin/npm')
->setNodeModulePath("/opt/cpanel/ea-nodejs16/lib/node_modules")
->setChromePath("/bin/chromium-browser")
->windowSize(1920, 1080)
->fullPage()
->save($output_file_path);
and boom, that is it