Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: roborob on April 28, 2013, 01:05:39 PM

Title: node.js
Post by: roborob 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:

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
Title: Re: node.js
Post by: althalus 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 (https://npmjs.org/package/pi-gpio). The boring part is already done for you, and you just have to know enough javascript to process the sensor input.
Title: Re: node.js
Post by: roborob 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.
Title: Re: node.js
Post by: althalus 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!
Title: Re: node.js
Post by: roborob 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.
Title: Re: node.js
Post by: althalus 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
Title: Re: node.js
Post by: Rich 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.
Title: Re: node.js
Post by: roborob 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?
Title: Re: node.js
Post by: althalus 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.
Title: Re: node.js
Post by: roborob 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 ... ?
Title: Re: node.js
Post by: althalus 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.
Title: Re: node.js
Post by: roborob 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.
Title: Re: node.js
Post by: Rich 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.
Title: Re: node.js
Post by: roborob on April 29, 2013, 12:39:43 AM
I stand corrected.
Title: Re: node.js
Post by: Rich 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.
Title: Re: node.js
Post by: roborob on April 29, 2013, 12:58:21 AM
Well that would explain a few things.  Strange that it just ignored the --overwrite rather than throw an error message (like invalid arg, etc.)
Title: Re: node.js
Post by: bmarkus on May 23, 2013, 05:00:48 PM
node.js is added to repo.
Title: Re: node.js
Post by: roborob on May 26, 2013, 02:03:16 PM
Thanks Béla! 
I was able to get everything complied and running, however this will save a ton of time on my next project.
Title: Re: node.js
Post by: gaspo100 on February 26, 2016, 08:00:35 PM
Hi Bela,

I'm using picore 7 and I don't seem to be able to find nodejs tcz in the repo. Has it been removed?

Thanks.
Title: Re: node.js
Post by: mocore on February 27, 2016, 07:12:41 AM

You could try to copy /6.x/armv6/tcz/nodejs.tcz

but i would just use the script called 'n'  for
"Simple flavour of node/iojs binary management, no subshells, no profile setup, no convoluted api, just simple."

@ raw.githubusercontent.com/tj/n/master/bin/n *

*you will need to install bash before you can use this script !

Title: Re: node.js
Post by: gavinmc42 on February 28, 2016, 08:19:43 PM
gaspo100

Did get nodejs working on version 6 piCore, have not tried it on version 7.
I ended up using busybox-httpd to serve web pages.
Mainly because i am behind a Uni firewall so installing npm packages etc was a pain.

I have had success installing/compiling on Raspbian then copying files to PiCore.
If not too many files are needed then it is simple, if files get installed in multiple directories then making a xxx.tcz is better.

Regards
Gavin
Title: Re: node.js
Post by: bmarkus on February 29, 2016, 12:01:23 AM
Hi Bela,

I'm using picore 7 and I don't seem to be able to find nodejs tcz in the repo. Has it been removed?

Thanks.

It is available in the armv7 repo and works fine on RPi2. Unfortunately node is detecting CPU type in runtime where armv6 detection is buggy resulting it doesn't work on RPi, so it is not in v6 repo. As soon as I find a patch or upstream fix the issue it will be back.
Title: Re: node.js
Post by: gaspo100 on February 29, 2016, 01:55:33 AM
It is available in the armv7 repo and works fine on RPi2. Unfortunately node is detecting CPU type in runtime where armv6 detection is buggy resulting it doesn't work on RPi, so it is not in v6 repo. As soon as I find a patch or upstream fix the issue it will be back.

Thanks Bela for the update. I'm running piCore 7 on the older arm-v6 board and needed something to run web services.

As the node is not available for the v6 and I didn't have much time testing node tcz from picore 6, I went C++ route (libevent / evhttp_*) and written a simple http service returning json data.
Title: Re: node.js
Post by: bmarkus on February 29, 2016, 02:34:32 AM
Actually the LTS 4.2.4 version in the repo. Will test the latest stable 5.x to see is it fixed or not by upstream.
Title: Re: node.js
Post by: patrikg on February 29, 2016, 04:29:11 AM
Tried the nginx in the 5 repo ??
http://tinycorelinux.net/5.x/armv6/tcz/nginx.tcz
Title: Re: node.js
Post by: bmarkus on February 29, 2016, 04:45:31 AM
Tried the nginx in the 5 repo ??
http://tinycorelinux.net/5.x/armv6/tcz/nginx.tcz

How is it related to node.js?
Title: Re: node.js
Post by: patrikg on February 29, 2016, 04:57:19 AM
Sorry for miss post this tips.
Tried to help with thinking of different http servers.
Not just busybox, lightttpd, apache.
Title: Re: node.js
Post by: bmarkus on March 01, 2016, 08:09:46 AM
node.tcz updated to 5.7.0 Now it works fine on both RPi1 and RPi2 boards.
Title: Re: node.js
Post by: gaspo100 on March 01, 2016, 09:10:58 PM
Thanks for that, I'll give it a try.
Title: Re: node.js
Post by: gavinmc42 on March 18, 2016, 08:24:22 AM
Don't forget to make mmcblk0p2 bigger.
node.tcz is over 6MB, caused me issues with tce-load -wi until  I remembered I just had the standard size partition
Works on Pi 3 too.

Will be interesting to try node for websocket video streaming the camera.
Done it with busybox-httpd on 1B's.
Title: Re: node.js
Post by: loppanjo on April 12, 2016, 05:34:18 PM
How do I get node working? I've managed to download it and when I try to use
'npm install -g express' I get the following error:
Code: [Select]
npm WARN checkPermissions Missing write access to /tmp/tcloop/node/usr/local/lib/node_modules
/tmp/tcloop/node/usr/local/lib
`-- express@4.13.4
  +-- accepts@1.2.13
  | +-- mime-types@2.1.10
  | | `-- mime-db@1.22.0
  | `-- negotiator@0.5.3
  +-- array-flatten@1.1.1
  +-- content-disposition@0.5.1
  +-- content-type@1.0.1
  +-- cookie@0.1.5
  +-- cookie-signature@1.0.6
  +-- debug@2.2.0
  | `-- ms@0.7.1
  +-- depd@1.1.0
  +-- escape-html@1.0.3
  +-- etag@1.7.0
  +-- finalhandler@0.4.1
  | `-- unpipe@1.0.0
  +-- fresh@0.3.0
  +-- merge-descriptors@1.0.1
  +-- methods@1.1.2
  +-- on-finished@2.3.0
  | `-- ee-first@1.1.1
  +-- parseurl@1.3.1
  +-- path-to-regexp@0.1.7
  +-- proxy-addr@1.0.10
  | +-- forwarded@0.1.0
  | `-- ipaddr.js@1.0.5
  +-- qs@4.0.0
  +-- range-parser@1.0.3
  +-- send@0.13.1
  | +-- destroy@1.0.4
  | +-- http-errors@1.3.1
  | | `-- inherits@2.0.1
  | +-- mime@1.3.4
  | `-- statuses@1.2.1
  +-- serve-static@1.10.2
  +-- type-is@1.6.12
  | `-- media-typer@0.3.0
  +-- utils-merge@1.0.0
  `-- vary@1.0.1

npm ERR! Linux 4.1.13-piCore_v7+
npm ERR! argv "/tmp/tcloop/node/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! path /tmp/tcloop/node/usr/local/lib/node_modules
npm ERR! code EROFS
npm ERR! errno -30
npm ERR! syscall access

npm ERR! rofs EROFS: read-only file system, access '/tmp/tcloop/node/usr/local/lib/node_modules'
npm ERR! rofs This is most likely not a problem with npm itself
npm ERR! rofs and is related to the file system being read-only.
npm ERR! rofs
npm ERR! rofs Often virtualized file systems, or other file systems
npm ERR! rofs that don't support symlinks, give this error.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/tc/testpage/npm-debug.log

Any ideas on how to solve?
Title: Re: node.js
Post by: bmarkus on April 12, 2016, 08:02:20 PM
On which piCore version and RPi board?
Title: Re: node.js
Post by: loppanjo on April 13, 2016, 02:12:56 AM
piCore 7.0 RPi 2
Title: Re: node.js
Post by: bmarkus on April 13, 2016, 07:11:50 AM
Confirmed, it is an issue with loop mounting node.tcz I will fix it in May. As a temporary fix create an empty directory, loop mount node.tcz and copy content to file system, it will work.

Code: [Select]
sudo su
cd /
mkdir node
mount -o loop /mnt/mmcblk0p2/tce/optional/node.tcz /node
cp -r /node/usr /

Make sure it is not loop mounted already, remove node.tcz from onboot.lst

Alternative solution to copy all extensions to RAM at startup if they leave free RAM.

Code: [Select]
sudo touch /mnt/mmcblk0p2/tce/copy2fs.flg
sudo reboot

will make it. In this case node.tcz must be in onboot.lst
Title: Re: node.js
Post by: loppanjo on April 13, 2016, 09:40:31 AM
Which solution is most "clean"?
Title: Re: node.js
Post by: bmarkus on April 13, 2016, 11:05:32 AM
Which solution is most "clean"?

Most clean is to fix tcz in repo. Offered solutions are different but both working.

One boots a bit slower and using more memory, other requires some scripting. Try each version to learn TC :)