in an older blog post i described how to host node.js for free using heroku. now i show a way how to install node.js, npm and composer on any other shared host without root privileges with just a few lines of code. you can install packages, deploy vue.js applications or just start an express.js server. we always work in the user directory and use nvm - the node package manager.
It is important to make sure that composer and node are not present and that the following lines do not produce any output:
16c389ff1cdd9380cc5f9244775eb6c8
First, we define temporary environment variables that we will need later. To do this, we specify the user's home directory (usually ~/, on some shared hosts also /www/htdocs/xxxxxxx/) and the desired PHP version (for example, /usr/bin/php72 with the provider All-Inkl , /usr/local/bin/php7-72LATEST-CLI with DomainFactory ).:
16c389ff1cdd9380cc5f9244775eb6c8
Now we'll ensure that PHP is running in its latest version on the console. To do this, we'll create a new folder in the home directory, create a symbolic link, and add the directory to the beginning of the PATH environment variable.
16c389ff1cdd9380cc5f9244775eb6c8
Now we install global composer by downloading, checking and executing the installation script, then also placing composer.phar in the user directory and creating a symlink again:
16c389ff1cdd9380cc5f9244775eb6c8
We use nvm to install Node.js. This is a Bash script that's actually designed to make switching between Node versions easy. Here, we're taking advantage of its feature that it installs Node.js without requiring root privileges.:
16c389ff1cdd9380cc5f9244775eb6c8
With me a small correction in the .bashrc was still necessary:
16c389ff1cdd9380cc5f9244775eb6c8
Now we can install and activate the current stable version of Node.js:
16c389ff1cdd9380cc5f9244775eb6c8
With the help of nvm we can also easily switch versions.
16c389ff1cdd9380cc5f9244775eb6c8
I was able to perform all these steps without any problems with several German shared hosting providers. Some hosts have issues with symbolic links, but this can also be resolved using alias definitions . For example, the following .bashrc file works for DomainFactory.:
16c389ff1cdd9380cc5f9244775eb6c8
There are also issues accessing `/proc/stat` in virtual/shared environments, which is why, for example, the Node function `os.cpus()` returns `undefined` instead of the correct core count. This leads to error messages like "Cannot read property 'length' of undefined" when installing npm packages. I was able to resolve the problem by using a recent Node.js version (e.g., 11.15.0) that addresses the issue.