Friday, September 7, 2018

How to install node.js on openelec Kodi

Yet another short how to, I need node.js installed on my OpenElec Kodi box so I can get Google Home to control it. It took a bit of googling and some file editing.

ssh root@box ip

Should be in /storage

Run:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash

It will produce a message about adding some lines to .profile instead of .bashrc, that's okay. Check /storage/.profile, it should have a couple of lines like this:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

Log out, then ssh back to your Openelec box, this will force the new addition to .profile to be used.

Next, fix the nvm script so it works on Openelec.

cd .nvm
nano nvm.sh
Do a "Where Is" command in nano, search for " ls ", that's space, l, s, space, we're looking for an ls command. There are 3 of these:

ls -1qA

Remove the 'q' from all 3, the busybox sh version of ls doesn't support the 'q' option, and that's okay too.

Now install node.js:

nvm install node

This might take a minute or two.

Run the nvm "use" command:

nvm use node

You should see something like:

Now using node v10.10.0 (npm v6.4.1)

Test that node is working:
node -v
Output: v10.10.0

Test that npm (node package manager) works
npm -v
Output: 6.4.1

Update, 27 Sep 18: 
I should have mentioned that I added this to my autostart.sh script:

cd .config
nano autostart.sh

Add this line:

(sleep5;cd /storage/node/;nohup /storage/.nvm/versions/node/v10.10.0/bin/node /s
torage/node/server.js >> /storage/node/log.txt &) &


The 'sleep' waits a few seconds for the previous command to finish, 'nohup' lets the command continue to run uninterrupted, then there is the actually command with the full path or it won't work even though it's in the path, then the 'server.js' is the configuration, and last output to a log file.

1 comment:

Krr said...

u rock man, just what i was looking for <3