RPI_NODE_P5.JS
Posted by kll on October 05 2019 17:48:18
having a local server to play p5.js should be easy with a Raspberry Pi
using Node and Express server.

current update / info:
Raspbian GNU/Linux 10
DEBIAN buster
Linux version 4.19.66-v7+
Raspberry Pi 3 Model B Plus Rev 1.3
inet 192.168.1.204
cpu-temp=52.1'C
date: Sat 2019-10-05 17:44:44

already installed:
pi@RPI:~/projects/p5js $ node -v
v10.15.2


follow my own article here
( in a temp dir what later is deleted, do )
wget https://nodejs.org/dist/latest/node-v12.11.1-linux-armv7l.tar.xz
tar -xvf node-v12.11.1-linux-armv7l.tar.xz
cd node-v12.11.1-linux-armv7l
sudo cp -R * /usr/local/
sudo reboot

pi@RPI:~/projects/p5js $ node -v
v12.11.1
pi@RPI:~/projects/p5js $ npm -v
6.11.3


old way:
mkdir myapp
cd myapp
npm init
npm install express --save

new way:
sudo npm install -g express-generator
/usr/local/bin/express -> /usr/local/lib/node_modules/express-generator/bin/express-cli.js
+ express-generator@4.16.1
added 10 packages from 13 contributors in 2.778s

express --view=pug myapp
cd myapp
npm install
DEBUG=myapp:* npm start

> myapp@0.0.0 start /home/pi/projects/p5js/myapp
> node ./bin/www
myapp:server Listening on port 3000




lazy as usual, i go my newer sketch ( to be sure to catch a 0.9.0rev ) and download it.
( note: that downloads contain all files flat structure, so later should clean up )
unzip and copy all to
myapp/public/
restart server and WORKS
inside my network from a PC browser ( firefox ) call
http://192.168.1.204:3000/
manually i combine it with a test reading a csv file from assets, but see in console only



made also a
nano start#!/bin/sh
# p5js/myapp/start
MYPATH='/home/pi/projects/p5js/myapp'
echo '5s'
env sleep 5s
echo 'start node express 5pjs webserver, stop with [ctrl][c]'
cd $MYPATH
DEBUG=myapp:* npm start


chmod +x start
./start


well, to start that start you would need to go to that directory first...
nano start.desktop[Desktop Entry]
Version=1.0
Name=start
Name[en_GB]=start
Comment='node express p5js server'
Exec=lxterminal -e '/home/pi/projects/p5js/myapp/start'
Icon=kll_favicon.png
Terminal=false
Type=Application
Categories=Utility;KLL;
StartupNotify=true


and that you might copy to your desktop. OR
at
/home/pi/.config
create a /autostart subdirectory and copy that start.desktop in:
/home/pi/.config/autostart/start.desktop
( and reboot )



failed with build p5js editor


also ref to Processing forum question
that is from the coding train, but not use the p5.js at all,

so just for test i replaced the index.html ( from p5.js ) with this
but the local csv file i tested already,
assets/test.csv
and get

so i renamed that index.html to test.html,
got the original data from the coding train website and put it also under assets/
and call the page with:
http://192.168.1.204:3000/test.html
manually:



test more @Kent's csv script, this works