jjudge's avatar

From zero to being able to being able to enter "npm" commands

Got a WHM/cPanel server and am installing Laravel with all the trimmings in an account. Part of the install involves running npm commands. I am trying to understand what needs to be installed and where , in order to do this.

Searching for this, there are many mixed instructions on what to do. I have not been able to find any articles that explain just what is needed and how it interacts. For example:

  • What needs to be installed on the operating system globally, perhaps maintain by yum or whatever is used for OS package management?
  • What needs to be built from source, due to their now being any official packages for the OS?
  • What needs to be installed in the account where Laravel is being installed?

I'm not just looking for a series of commands to blindly run. I would like to understand what those commands are doing and where, so I know what needs to be maintained. I'm technically literate, so techy is fine :-)

Update: the underlying OS is CentOS 7.

0 likes
1 reply
jjudge's avatar

Just found these instructions which got me up and running:

https://hostiso.com/how-to-install-setup-node-js/

This will install node and npm in your local account, so nothing needs to be installed globally on the server. node is a compiled binary, while npm is a JavaScipt script that runs with node as its interpreter.

The latest code is downloaded as an archive from here: https://nodejs.org/en/download/ then expanded to a directory in the account.

The binary node is copied from the extracted archive to the bin directory in the account. Now, I found that the bin directory (even though it did not exist until I created it) was already in my PATH. I guess that is a WHM or cPanel feature.

After copying the node binary, the npm script and a number of its required siblings and support scripts are symbolically linked into the bin directory. This means the extracted node archive must not be moved, so make sure it is in an appropriate page. I extracted it to nodejs/ in the home directory of the domain account.

And that was it. Both node and npm are then available as commands when I log in, and that is what Laravel needs to do its asset management, downloading, compiling, minimising, etc.

I have kept the description to just the concepts above, and left the detailed commands to the page I linked at the top. It's all pretty simple in the end, just four or five commands. Updating the commands will just involve repeating the same steps, which take just a couple of minutes.

Of course, laravel will then add layers to that, with its own npm packages that run their own commands (interpreted by node), but that's another level. Getting node and npm was the task here, just giving Laravel what it needs to do its thing.

1 like

Please or to participate in this conversation.