WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: node.js  (Read 35503 times)

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
node.js
« on: April 28, 2013, 01:05:39 PM »
Hi everyone,

I would like to use node.js on the Raspberry as a robotics platform.  My thought behind this is the non-blocking, event driven I/O model of node is a great fit for event driven nature of sensors and other devices.

Here are the challenges as I see them:
  • Compile node.js for the arm platform.  node is written in C++
  • Write a node.js "Addon" that detects sensor input, and raises events in node
  • Package and publish the result

I have had a couple classes in C/C++ so I am a novice, but not afraid to get my hands dirty, however if there are some other people who think this is a worthwhile project I would welcome any help I could get.

I think it goes without saying this would be an open source project.

So, what do you think?  Anyone interested?

For future reference:
http://wiki.tinycorelinux.net/wiki:creating_extensions
« Last Edit: April 28, 2013, 02:58:39 PM by roborob »

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: node.js
« Reply #1 on: April 28, 2013, 07:15:54 PM »
I've been planning on compiling a tcz for node.js on the pi, just haven't found the time yet. (Also: submitting a bunch of TCZs I've already built). I'll *probably* do it this weekend, unless you're feeling motivated enough to try.

As for detecting sensor input, take a look at pi-gpio. The boring part is already done for you, and you just have to know enough javascript to process the sensor input.

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
Re: node.js
« Reply #2 on: April 28, 2013, 07:33:43 PM »
Hi althalus,

I am in the process of compiling a tcz, however it is pretty slow going as it is my first time.  Thanks for the pi-gpio mention, I was so focused on piCore that I didn't think to check NPM.

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: node.js
« Reply #3 on: April 28, 2013, 07:43:33 PM »
Compiling directly on the pi is always going to be slow going (especially if you make really stupid rookie mistakes like I did and forget to set the clock). Good luck!

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
Re: node.js
« Reply #4 on: April 28, 2013, 08:19:33 PM »
What a pain.  I am having a bit of trouble compiling.

Here are my steps so far:

Traceback:
  File "tools/gyp_node", line 11 in module import gyp
ImportError: No module named gyp

Do my steps look correct?  I will try 0.10.4 and see if there is any difference.  If anyone can spot what I am doing wrong I would be grateful for the help.
« Last Edit: April 28, 2013, 11:00:55 PM by roborob »

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: node.js
« Reply #5 on: April 28, 2013, 09:04:11 PM »
Try the following:
Code: [Select]

mkdir nodejs
cd nodejs
wget http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
tar -vzxf node-v0.10.5.tar.gz
cd node-v0.10.5
./configure #I assume this was just a typo when posting
make # maybe compiling and installing separately will resolve your error. Some applications are fussy like that.
sudo make DESTDIR=/tmp/nodeinstalldir install # Keep node's files separate so we can package them easier

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: node.js
« Reply #6 on: April 28, 2013, 09:22:47 PM »
Hi roborob
Quote
Traceback:
  File "tools/gyp_node", line 11 in module import gyp
ImportError: No module named gyp
Maybe a missing dependency.  npm  has a  gyp.

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
Re: node.js
« Reply #7 on: April 28, 2013, 11:03:59 PM »
Hi,

althalus, yes on the type-o, separate make and install did not help, nor did setting the destdir

Rich, this is the tar file right off their site and there are no complaints of a missing dep in their forums.  the prev tar (v0.10.4) behaves the same

Thanks guys, I will keep trying.

[edit]
Actually, Rich got me thinking.  I tried tar -t and there was a very long list of files.  However, when extract tar stops pretty quickly with:
can't open: 'node-v0.10.5/tools/wrk/src/ae.h': File exists

I must have missed that the first time through.  I tried the tar --overwrite option but that did not seem to help. 

Any thoughts?
« Last Edit: April 28, 2013, 11:12:39 PM by roborob »

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: node.js
« Reply #8 on: April 28, 2013, 11:18:00 PM »
Hi roborob
Quote
Traceback:
  File "tools/gyp_node", line 11 in module import gyp
ImportError: No module named gyp
Maybe a missing dependency.  npm  has a  gyp.
gyp is included in node.js's source.

Nodejs's listed dependencies (on their wiki):
Code: [Select]
GNU make 3.81 or newer. Pre-installed on most systems. Sometimes called gmake.

python 2.6 or 2.7. The build tools distributed with Node run on python.

libssl-dev (Node v0.6.x only.) Can usually be installed on *NIX systems with your favorite package manager. Pre-installed on OS X.

libexecinfo (FreeBSD and OpenBSD only.) Required by V8. pkg_add -r libexecinfo installs it.

[edit]
Actually, Rich got me thinking.  I tried tar -t and there was a very long list of files.  However, when extract tar stops pretty quickly with:
can't open: 'node-v0.10.5/tools/wrk/src/ae.h': File exists

I must have missed that the first time through.  I tried the tar --overwrite option but that did not seem to help. 

Any thoughts?
Downloaded and extracted on my pi, didn't notice that error message at all.

When you ran make and make install separately, was the failure in running make or make install?

According to a bit of googling, people have successfully compiled v0.10.2 on the pi.

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
Re: node.js
« Reply #9 on: April 28, 2013, 11:32:59 PM »
Hi althalus,

OK it seems to be compiling now... I re-read all the posts and something you wrote sparked an idea.  Since not all the files were being extracted (hence the failure during make) I began to suspect it may be a path or even a drive issue.  I changed to the /tmp directory and created a subdirectory called node.  Then I changed to that directory and ran tar referencing the full path to the downloaded file.  This time all the files extracted.  From there ./configure and sudo make install ran normally. 

The difference being /tmp is on the SD card, and my downloads (and /tce) directory is on a USB drive.  I am attempting to use a USB drive (mounted at boot time (sda1)).  Béla mentioned that the RPi USB code may be a bit weak in a different forum post.  However when I tried installing apps and running backup it seemed fine.  Could this be a USB issue?  A path issue?  Or ... ?
« Last Edit: April 28, 2013, 11:54:32 PM by roborob »

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: node.js
« Reply #10 on: April 29, 2013, 12:06:35 AM »
My understanding of the USB issues, is that if you're running into USB  problems, it'll be fairly evident from the get-go that there's a problem, but I'm not all that qualified to comment on the pi's USB stack.

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
Re: node.js
« Reply #11 on: April 29, 2013, 12:14:54 AM »
Hi,

I tend to agree that if there is going to be problems with a drive, it will show up right away.  Since moving the /tce folder to the USB drive seemed OK I didn't give it a second thought.  I tested it by installing a few apps like bluefish and others.  I configured a static IP and ran backup.  There were no errors during the process and after rebooting everything seemed normal.  I am leaning more toward this being a path issue rather than USB.  Either way, I will most certainly keep this in mind moving forward.  It would be nice to understand what I did wrong, however at this point I am just happy to be making progress.  Speaking of which... almost 2 hours on the compile and still no errors.  Yay! (I think)

Next step build a package so others might benefit from this effort.  Thanks for hanging in there with me.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: node.js
« Reply #12 on: April 29, 2013, 12:38:42 AM »
Hi roborob
Quote
The difference being /tmp is on the SD card, ...
Really? I was under the impression that the PI version uses the same file system layout as X86, which would
place /tmp in RAM.

Offline roborob

  • Jr. Member
  • **
  • Posts: 58
Re: node.js
« Reply #13 on: April 29, 2013, 12:39:43 AM »
I stand corrected.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: node.js
« Reply #14 on: April 29, 2013, 12:55:00 AM »
Hi roborob
Quote
I tried the tar --overwrite option but that did not seem to help.
Do you have tar.tcz installed? The busybox version of tar doesn't have an  --overwrite  command line switch.