node.js what is node.js? - gateway/400 group like asynchronous rpg sub-procedures different threads...
TRANSCRIPT
Node.js
What is Node.js?
LPP OPS – watch this space… Node.js… Python… more coming… ( http://www.ibm.com/developerworks/ibmi/techupdates/opensource )
First, how do IBM i keep up?
Node.js, installation, PTFs, etc.?
What is Node.js?
Node.js® is a platform built on Chrome's JavaScript runtime
● easily building fast, scalable network applications
● event-driven, non-blocking I/O model
● lightweight and efficient
● perfect for data-intensive real-time applications
Node.js moves to IBM i
Node.js, like all successful Open Source, has many contributors● IBM i Node.js contribution
● DB2 access (new)● Toolkit XMLService (new)
XMLService
Yes, Node.js on IBM i!
Node.js® like asynchronous RPG sub-procedures
● Different threads sub-procedure tasks (same time)
● Callback when task completed
AsynchronousSynchronous
function cb(str) {}var conn1 = new xt.iConn(db, user, pwd, option);conn1.add(xt.iSh("sleep 10; date"));var conn2 = new xt.iConn(db, user, pwd, option);conn2.add(xt.iSh("sleep 10; date"));
var task1 = conn1.run(cb); // task 1 (async)var task2 = conn2.run(cb); // task 2 (async) XMLSERVICE REST interface
● task 1 and 2 are asynchronous● (typical node.js)
QSQSRVR DB2 BCI .0 PGM-sleep THDWQSQSRVR DB2 BCI .0 PGM-sleep THDW
Asynchronous(perfect)
XMLService
function cb(str) {}var conn = new xt.iConn(db, user, pwd, option);conn.add(xt.iCmd("CHGLIBL LIBL(MYLIB) CURLIB(MYLIB)"));var pgm = new xt.iPgm("ZZFAKE");pgm.addParam("a", "1A");pgm.addParam("b", "1A");pgm.addParam([ ["x","1A"], ["y", "1A"]);conn.add(pgm.toXML()); var task1 = conn.run(cb); // task 1
Synchronous(XML forced)
XMLService multi-part script conn.add()● task 1 is asynchronous, but ...● CHGLIBL occurs 1st, then PGM call
QSQSRVR DB2 BCI … CHGLIBL, then PGM call
XMLService
var task1 = task1(); // task 1 (not async)var task2 = task2(); // task 2 (not async)function cb(}function task1() { db.init(); db.conn(conf.Database); db.exec("SELECT LSTNAM, STATE FROM QCUSTCDT", cb); db.close(); return 0;};function task2() { db.init(); db.conn(conf.Database); db.exec("SELECT * from ANIMALS",cb); db.close(); return 0;};
Current db2i interface ... ● task 1 and task 2 are synchronous● (not typical node.js DB behavior)
QSQSRVR DB2 BCI … task 1, then task 2
Synchronous (DB2 not perfect)
DB2
function cb(str) {}var conn1 = new xt.iConn(db, user, pwd, option);var sql = new xt.iSql();sql.addQuery("call XMLSERVICE.iHANG()");conn1.add(sql.toXML());var conn2 = new xt.iConn(db, user, pwd, option);var sql1 = new xt.iSql();sql1.addQuery("call XMLSERVICE.iHANG()");conn2.add(sql1.toXML());
var task1 = conn1.run(cb); // task 1var task2 = conn2.run(cb); // task 2
XMLSERVICE REST interface ... ● task 1 and 2 are asynchronous● (typical node.js, xmlservice DB2 )
Asynchronous(perfect)
QSQSRVR DB2 BCI THDWQSQSRVR DB2 BCI THDW
XMLService
Debugbash-4.2$ node debug xmlservice.js < debugger listening on port 5858connecting... okbreak in xmlservice.js:9debug> nbreak in xmlservice.js:50 50 var arr = uri.host.split(":"); 51 var options = { 52 host: arr[0],debug> replPress Ctrl + C to leave debug repl> ixml'<?xml version=\'1.0\'?>\n<xmlservice><... (length: 562)'debug>
Safe Node.js on IBM i?
bash-4.3$ ls /QOpenSys/QIBM/ProdData/C++Compiler JavaVM Node OS400 SOIDeveloperTools NativeTools OPS SC1
bash-4.3$ ls /QOpenSys/QIBM/ProdData/Node/bin include lib notices.txt os400
bash-4.3$ export PATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/binbash-4.3$ export LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/libbash-4.3$ node --versionv0.10.29
Where is Nodejs now (mmm public)?
Mmm, playing with node,js in root file system of my system does NOT please me. I want your activities contained Ms. Bobby!
IBM i OPS GCC environment (chroot setup) ...
Node.js experiments are not going to mess up my system. And no more new LPARs. This is a job for PASE chroot.
== LPP OPS beta scripts ==... chroot_setup.sh - chroot environment, so you do not mess up your machine… pkg_setup.sh – install RPMs from any site… ( http://yips.idevcloud.com/wiki/index.php/PASE/OpenSourceBeta )== LPP OPS beta scripts ==
Ranger
Bobby
Lefty
Wild Bill
IBM i chroot (change '/' location)
chroot /QOpenSys/bobby /usr/bin/bsh
chroot /QOpenSys/ranger /usr/bin/bsh
chroot /QOpenSys/lefty /usr/bin/bsh
chroot /QOpenSys/wildbill /usr/bin/bsh'/' is .../QOpenSys/wildbill/(*)
'/' is …/QOpenSys/lefty/(*)
'/' is …/QOpenSys/bobby/(*)
'/' is …/QOpenSys/ranger/(*)
No problem, but you are not going to mess up my system, so chroot you.
No chroot, '/' is … /(*)admin
Initial chroot void (nothing here)
./chroot_setup.sh (fill the box)
( http://yips.idevcloud.com/wiki/index.php/PASE/OpenSourceBeta )
$ mkdir -p /QOpenSys/bobby$ chroot /QOpenSys/bobby /bin/bsh/bin/bsh: No such file or directory
$ cd /QOpenSys/QIBM/ProdData/OPS/GCC $ ./chroot_setup.sh chroot_minimal.lst /QOpenSys/bobby **********************Live IBM i session (changes made).**********************
$ ./chroot_setup.sh chroot_OPS_NODE.lst /QOpenSys/bobby**********************$ mkdir -p /QOpenSys/bobby/home/bobby$ chroot_chown.sh bobby
./chroot_setup.sh (add Node.js)
When a user profile with a "." (dot) in their home directory path connects using ssh, sftp, or scp path the "/" (root) directory for that connected session is set to be the portion of the directory path prior to the "."
ssh, sftp, scp, with chroot directory...
On 400======> strTCPSVR SERVER(*SSHD)> mkdir -p /QOpenSys/bobby/home/bobby> CHGUSRPRF USRPRF(RANGER) LOCALE(*NONE) HOMEDIR(/QOpenSys/bobby/./home/bobby)
On laptop=========$ ssh bobby@myibmi
( http://yips.idevcloud.com/wiki/index.php/PASE/OpenSourceBeta )
$ ssh bobby@ut30p30bobby@ut30p30's password: $ ls /QOpenSys bin dev home lib sbin tmp usr$ export PATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/binPATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/bin: is not an identifier$ ksh$ export PATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/bin$ export LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/lib$ node --versionv0.10.29$
( http://yips.idevcloud.com/wiki/index.php/PASE/OpenSourceBeta )
Bobby safely running node.js in chroot ...
Ms. Bobby! Free free to conduct your node.js experiments in your private chroot jail. No access /QSYS.LIB, well, except for DB2 connect. Best of all, you are not messing up OPS node.js or PASE.
No access /QSYS.LIB
Bobby's node.js chroot hack proofing ...
$ mkdir myapp $ cd myapp$ lsmy1st.js$ node my1st.jsServer running at http://ut30p30:8080/
$ ssh bobby@ut30p30bobby@ut30p30's password: $ ls /QOpenSys bin dev home ...
No access /QSYS.LIB
$ cat my1st.jsvar http = require('http');http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n');}).listen(8080, 'ut30p30');console.log('Server running at http://ut30p30:8080/');
Bobby's node.js chroot Hello World ...
Bluemix Node.js remote IBM i?
http://myibminodejs.mybluemix.net/
(application not always running)
Web Application: http://myibminodejs.mybluemix.net/ Git repository: https://hub.jazz.net/project/rangercairns/MyIBMiNodeJs/overview
(application not always running, but source available)
Bluemix app move to IBM i?
Git repository: https://hub.jazz.net/project/rangercairns/MyIBMiNodeJs/overview
Bobby download Git ...
Download and unzip on your pc. Transfer all files up to IBM i, into your chroot location, same directories as in zip (/home/bobby/MyIBMiNodeJs).
Download
$ cd /home/bobby/MyIBMiNodeJs$ ls License.txt instructions.md publicREADME.md lib viewsREADME.txt manifest.yml xmlserviceprovider.jsapp.js package.json
Bobby chroot application ...$ ssh bobby@ut30p30bobby@ut30p30's password: $
$ ksh$ export PATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/bin$ export LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:/usr/lib$ node --versionv0.10.29
Bobby chroot application ...
$ node app.jsmodule.js:340 throw err;Error: Cannot find module 'express'
$ npm install expressmodule.js:340 throw err;Error: Cannot find module 'npmlog'
Never goes perfectly, most presentations lie about 'ops', this one shows it all.
Bobby chroot application ...$ cd /QOpenSys/QIBM/ProdData/Node/bin$ ls ../lib/node_modules/npm/bin/npm-cli.js../lib/node_modules/npm/bin/npm-cli.js$ ln -sf ../lib/node_modules/npm/bin/npm-cli.js npm$ ls -l npmlrwxrwxrwx 1 bobby 0 76 Nov 9 07:48 npm -> ../lib/node_modules/npm/bin/npm-cli.js$ cd$ npm --version1.4.14
$ npm install expressnpm ERR! fetch failed https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.1.tgznpm ERR! fetch failed https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgznpm ERR! fetch failed https://registry.npmjs.org/fresh/-/fresh-0.2.0.tgznpm ERR! fetch failed https://registry.npmjs.org/batch/-/[email protected] node_modules/express
Never goes perfectly, most presentations lie about 'ops', this one shows it all.
Bobby chroot application ...
$ node app.jsApp started on port 3000events.js:72 throw er; // Unhandled 'error' eventError: listen EADDRINUSE
$ export VCAP_APP_PORT=8081$ export VCAP_APP_HOST=ut30p30$ node app.jsApp started on port 8081module.js:340 throw err; ^Error: Cannot find module 'jade'
Never goes perfectly, most presentations lie about 'ops', this one shows it all.
Bobby chroot application ...$ npm install jadenpm ERR! fetch failed https://registry.npmjs.org/character-parser/-/[email protected] node_modules/jade$ node app.jsApp started on port 8081
This IBM i application moved from Bluemix is remotely chatting with Yips IBM i machine. It works my_IBMi<2>yips_IBMi, but, demo assuming your IBM i can talk REST web services outside firewall to HTTP (of course).
Bobby chroot (MyIBMiNodeJs/lib) ....
Same IBM i toolkit found in /QopenSys/QIBM/ProdData/Node/os400/xstoolkit/lib.Copied to Bluemix for application http://myibminodejs.mybluemix.net/
$ pwd/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib$ ls -1idataq.jsinetwork.jsiobj.jsiprod.jsirest.jsistoredp.jsitoolkit.jsiuserSpace.jsiwork.jsixml.js
Bobby application xmlserviceprovider.js...
Bobby application xmlserviceprovider.js...
Bobby application xmlserviceprovider.js...
Bobby application xmlserviceprovider.js...
Bobby application app.js (control)...
Bobby app.js (control)...
get (read)
post (write)
IBM i toolkit
Bobby app.js index.jade (/) ....
Bobby app.js cat.jade (/cat)....
Bobby app.js big.jade (/big) ....
Also, Ruby Rails use Node.js?
PowerRuby Rails Asset Pipeline requires JavaScript (Node.js)● framework concatenate JavaScript and CSS assets ● hybrid lang assets CoffeeScript, Sass and ERB.● CoffeScript compiles into JavaScript (via Node.js)
> rails new appname
Rails Asset Pipeline
# Assignment:number = 42opposite = true# Conditions:number = -42 if opposite# Functions:square = (x) -> x * x# Arrays:list = [1, 2, 3, 4, 5]# Objects:math = root: Math.sqrt square: square cube: (x) -> x * square x
var cubes, list, math, number, opposite, square;number = 42;opposite = true;if (opposite) { number = -42;}square = function(x) { return x * x;};list = [1, 2, 3, 4, 5];math = { root: Math.sqrt, square: square, cube: function(x) { return x * square(x); }};
PowerRuby Rails Asset Pipeline
Questions?