Before we go any further, now is a good time to add Node and NPM. To ensure success it's a good idea to install identical versions of Node and NPM as are found in your local development environment. If you don't have node installed - go ahead and download the Windows installer and install it. It's probably better not to install the very latest version. Rather choose a version that has LTS (Long Term Support). To figure out what version of node you have installed type
node -v
On your Command Line Interface on your local development machine (in my case Windows). Then type
npm -v
Take note of the specific version numbers of both node and npm. We will use these specific version numbers when intsalling node and npm.
You can install node using apt but you don't have much control over specific version numbers the better option is to use Node Version Manager. NVM is designed to install node on a per user basis allowing you to have a different version of node installed for different users. Given that we have set up a specific user account for our application, this will suit us well.
To download nvm, make sure your logged in to your application account and in the home folder (in my case tennisclub) and then type the following command into the Linux shell interface
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
This downloads nvm and executes it using the Bourne Shell (bash). Then, to install this into the user shell startup script type
source .bashrc
Having set this up the nvm command is now available to us and we can use it to install a specific version of node.The version of node running on my local development machine is 18.12 so to match that on my Linux VPS I will install that version - you should replace 18.12 with the version on your machine
nvm install 18.12
Then to install the specific version of npm type
npm install -g npm@8.4.1
To verify that the correct version of node is installed type
node -v
To verify the npm version type
npm -v
Once these are installed correctly, move-in to your application folder under the user home folder. In my case, this is called tc01. To pull down all the same modules that were installed on the development machine into the node_modules folder type
npm install
Once that's finished, to build all the node packages your application is using type
npm run prod
This will compile all the node javascript packages used in the application into two files app.css and app.js so that they will load faster and behave consistently on users' devices.