11

I am trying to install node.js on my Raspberry Pi as well as GPIO.

I am running a brand new install of Debian Jessie

I could get nodejs v.0.10.29 installed. No matter what I do, this is pretty much the most recent package I have been able to install even if a lot of post I read are speaking of version 4.0.0.

However v0.10.29 is running and I could run a simple http server.

The problem comes when I try to install GPIO. I have tried the following;

  • rpi-gpio
  • pi-gpio
  • onoff

I can't get any of them to work and I have played around trying anything I could find on the web to fix it. I have tried pretty much everything.

So, since I probably messed up a lot of things, I reinstalled the OS Debian {Ed: Raspbian} Jessie and will give it another shot.

From there, what should I do after my OS is installed to get this to work?

Anyone have a good set of instruction for this - because I am probably missing something, right?

If anyone is willing to help I would gladly follow instructions and post any error messages I'm getting, because so far this is all I have been getting.

So I guess I will start with:

sudo apt-get update

What's next?

EDIT #1 Nodejs v0.10.29 is installed

I have installed Nodejs as suggested by Joan:

wget https://nodejs.org/dist/v4.3.1/node-v4.3.1-linux-armv6l.tar.xz
tar xf node-v4.3.1-linux-armv6l.tar.xz  
cd node-v4.3.1-linux-armv6l/ 
sudo cp -R * /usr/local

nodejs -v 

returned;

v0.10.29

EDIT#2 pi-gpio install

Now that node is installed I have try to turn a led on on pin 18 and got the following error;

module.js:340 
throw err; 
^ 
Error: Cannot find module 'pi-gpio' 
at Function.Module._resolveFilename (module.js:338:15) 
at Function.Module._load (module.js:280:25) 
at Module.require (module.js:364:17) 
at require (module.js:380:17) 
at Object.<anonymous> (/home/pi/NODE/http.js:22:12) 
at Module._compile (module.js:456:26) 
at Object.Module._extensions..js (module.js:474:10) 
at Module.load (module.js:356:32) 
at Function.Module._load (module.js:312:12) 
at Function.Module.runMain (module.js:497:10)

So I have installed pi-gpio using npm;

sudo npm install pi-gpio

I am now getting this error;

Error when trying to open pin 18
/bin/sh: 1: gpio-admin: not found

Error when trying to close pin 18
/bin/sh: 1: gpio-admin: not found

So I will now install gpio-admin.

And this where it get messy because gpio-admin is old and wont install on the Debian Jessie So if anyone can come up with a way to turn on a led from Nodejs under Debian Jessie that would be awesome.

MadeInDreams
  • 306
  • 1
  • 2
  • 10

2 Answers2

7

For example to install RPi nodejs version 4.3.1 (see below for other versions)

wget https://nodejs.org/dist/v4.3.1/node-v4.3.1-linux-armv6l.tar.xz
tar xf node-v4.3.1-linux-armv6l.tar.xz  
cd node-v4.3.1-linux-armv6l/ 
sudo cp -R * /usr/local

Check installation with

node -v

Different versions are available from https://nodejs.org/dist/

For the Pi2B make sure you download a linux-arm7l build, for all other Pis make sure you download a linux-arm6l build.

joan
  • 71,024
  • 5
  • 73
  • 106
  • Thank you will try that version. So far that distributor always returned me 404. – MadeInDreams Feb 22 '16 at 18:18
  • Yeah I'm still getting a 404 response – MadeInDreams Feb 22 '16 at 18:20
  • 1
    I followed those instructions just before I posted and have just repeated the wget without problem. Can you ping nodejs.org? – joan Feb 22 '16 at 18:24
  • yes I can. Do I have to sudo wget? – MadeInDreams Feb 22 '16 at 18:28
  • 1
    No, sudo is not required (it wouldn't give a 404 error). Make sure you cut&paste the wget line. You may prefer a later version. Look in https://nodejs.org/dist and make sure you download an arm6l version. I'm not sure if 6l will also work on a Pi2B. – joan Feb 22 '16 at 18:32
  • Got it. But is it normal that nodejs -v return v0.10.29? – MadeInDreams Feb 22 '16 at 18:37
  • I have no idea. I don't use node.js. To see the node version try node -v. Hopefully that will be whatever you ended up downloading. – joan Feb 22 '16 at 18:42
  • To clarify on my Pi, after downloading version 5.6 I get npm -v 3.6.0, nodejs -v V4.2.6, node -v v5.6.0. I have no idea what those numbers actually mean. – joan Feb 22 '16 at 18:46
  • @MadeInDreams make sure that you're typing in the *.tar.xz name correctly (note that the last char before the extension is a lowercase "L" not a "1", could be easily mistaken). I have just run through these steps and successfully updated node to v4.3.1. node -v should return v4.3.1, not the older version that you're returning. – Thomas Stringer Feb 22 '16 at 22:06
2

Figured out how to get *GPIO* working with *Nodejs*.

Let me tell you that this was far from being Plug and play.

**OS** : *Raspbian Jessie*

**Nodejs**: *Version 4.3.1* ( Credit to joan)

Note that you should remove any old installation of *Nodejs*.

I have updated *npm* with the following command;

sudo npm install -g npm@latest

Then I have installed *gpio v0.2.7*;

 sudo npm install gpio

and got the folowing warning;

npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json'

So I will have to deal with that.

Then I have installed *rpi-gpio*;

sudo npm install rpi-gpio

Still got the warning about package.json. At this point my script was working I could reach the server and my led light came on.

Other install I have made due to warning and errors:

sudo npm install graceful-fs@^4.0.0
sudo npm install node-gyp

I'm not sure that the last 2 installs where needed but it ended up working so you might want to try that to.

MadeInDreams
  • 306
  • 1
  • 2
  • 10