Updating node.js to latest version

Started by Scram, April 24, 2016, 04:46:31 PM

Scram

This weekend I started to integrate Telegram support for my gateway using this framework.
https://github.com/yagop/node-telegram-bot-api
Actually it's working really well and makes up a very good integration with the mobile. Especially the feature of creating own keyboard layouts makes it possible to create really nice and extremely quick two way real time user interfaces.  But there's a known issue with node.js version 0.10.28.
https://github.com/yagop/node-telegram-bot-api/issues/52
In combination with this version it will eat RAM continously which makes me think about updating to latest Node.js version were it should be fixed.
Did anybody try this in combination with a Raspberry pi 2 and the Code from Felix? I am not really skilled in programming so I'm a bit unsure whether this might work ok?
How does an update of node.js work? Would I have to update any libraries as well?

Scram

#1
Ok - doesn't seem to be a popular matter  ;D

I decided to be brave and try it out on my productive Gateway and voila - it seems to work ok with node.js version 4.4.3.

;D ;D ;D ;D

Here's what i did in case somebody needs to update node.js for whatever reason:

1. I installed a tool called nvm (=Node.js version manager) as updating via npm seems to be a bit wonky especially in more complex setups.

Get nvm:
sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

-> restart terminal session so nvm is usable in bash

nvm should work if nvm --version does something (0.31.0 in my case)

2. Stop everything using node.js
- sudo service gateway stop
- pkill node

3. Update node.js by issuing:
- nvm install x.y.z (in my case the stable V4 was 4.4.3)

4. Check current node.js version with:
- node -v

In my case it updated to node.js 4.4.3 and told me:

Now using node v4.4.3 (npm v2.15.1)

5. In /etc/init/gateway.conf this line must be changed to use the new node binary (this is only when updated via nvm tool)
exec sudo -u pi /home/pi/.nvm/versions/node/v4.4.3/bin/node /home/pi/gateway/gateway.js >> /home/pi/gateway/logs/gateway.sys.log 2>&1

6. I rebooted the whole thing (dunno if it helps but at least it should not do any bad  ::))

7. Check logfile in ~/gateway/logs/gateway.sys.log

Edit:

I noted that it is a good idea to delete the whole /home/pi/gateway/node_modules directory and reinstall everything new via npm install. This seems necessary as some dependencies seem to be hard coded. Next thing i noticed was that node V4 wants to compile things differently. When compiling cpp files e.g. within module "Serialport" it insists on using g++ V4.8 as minimum. My distribution is Raspian Wheezy so i was on gcc/g++ 4.6. To deal with this issue i followed this guide with success:
https://github.com/fivdi/onoff/wiki/Node.js-v4-and-native-addons

It seems like all my problems are solved now. No more RAM is eaten away in 48hrs testing. Things run stable and smooth.

Felix

Thanks for sharing this, it's a good reference for anyone looking to upgrade node.

jkarras

On a Raspberry Pi 2 or 3 running a current version of Rasbian you can also just use the official deb's to upgrade.

https://github.com/nodesource/distributions

curl -#L https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs


Kylix


Kylix

I upgraded node.js to v7.0.0 and the gateway works perfectly.

Lukapple

#6
Sorry for resurrecting old topic.
How did you update to node.js v7.0.0?

I've updated following part of script gatewaysetup.sh:
echo -e "${CYAN}************* STEP: Install NodeJS *************${NC}"
if [[ "$NODEARCH" == "armv6l" ]] ; then
  mkdir ~/tempnode -p
  cd ~/tempnode
  wget https://nodejs.org/dist/v7.0.0/node-v7.0.0-linux-armv6l.tar.gz
  tar -xzf node-v7.0.0-linux-armv6l.tar.gz
  sudo rm node-v7.0.0-linux-armv6l.tar.gz
  sudo rm -rf $NODEDIR
  mkdir -p $NODEDIR
  sudo mv node-v7.0.0-linux-armv6l/* $NODEDIR
  sudo rm -rf ~/tempnode;
  cd ~/


and now installation stops here:

From https://github.com/LowPowerLab/RaspberryPi-Gateway
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
npm WARN deprecated [email protected]: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
[    ..............] \ fetchMetadata: WARN deprecated [email protected]: All versions below 4.0.1 of Nodemailer are deprecated. See https:/


No error, it just runs for a very long time... still waiting to complete...

EDIT: works fine with v5.4.1

Kylix

Hi Lukapple,

I played long time ago with it but I just followed Scram's post no. 2 for installing version 7. I think it was something like:

nvm install 7.0.0