Nextjournal / Jan 14 2020
Node.js Environment
Setup
Build the node environment
Install dependencies, Node, and Yarn.
apt-get -qq update DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends \ build-essential gfortran cmake automake libtool libltdl-dev pkg-config \ libzmq3-dev apt-get clean rm -r /var/lib/apt/lists/*
Download Node.js and Yarn binaries.
FILENAME="node-v${NODEJS_VERSION}-linux-x64.tar.xz" FILEURL="https://nodejs.org/dist/v${NODEJS_VERSION}/${FILENAME}" curl -O https://nodejs.org/dist/v${NODEJS_VERSION}/SHASUMS256.txt wget --progress=dot:giga ${FILEURL} grep $FILENAME SHASUMS256.txt | sha256sum -c - cp $FILENAME /results/ FILENAME="yarn-v${YARN_VERSION}.tar.gz" FILEURL="https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/${FILENAME}" wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import wget --progress=dot:giga ${FILEURL} ${FILEURL}.asc gpg --verify ${FILENAME}.asc cp $FILENAME /results/
Install Node.js.
mkdir -p /opt/nodejs cd /opt/nodejs tar -Jxfnode-v10.16.2-linux-x64.tar.xzln -s node-v${NODEJS_VERSION}-linux-x64/ default
Install Yarn.
cd /opt tar -zxfyarn-v1.17.3.tar.gzln -s yarn-${YARN_VERSION} yarn
Install Jupyter.
pip install --upgrade jupyter jupyter_client
Install IJavascript.
npm install --unsafe-perm -g ijavascript ijsinstall
Check.
du -hsx / node -v npm version jupyter kernelspec list
Test
"use strict"; $$.async(); { let console = global.console; let $$ = global.$$; setTimeout(function() { console.log("Hello, world!"); $$.sendResult("Bye!"); }, 1000); }
'Bye!'
0.5s
Node Test (Javascript (Node.js))
Node.js
function Person(name) { this.name = name; } var peter = new Person("Peter"); var util = require("util"); console.log(util.inspect(peter)); // shown on stdout peter; // shown as an execution result Person.prototype.inspect = function inspect(depth) { return "Person named " + this.name; }; peter; Person.prototype._toHtml = function _toHtml() { var style = ( "display:inline-block;" + "padding:0.25em;" + "background:#ccc;" + "border: 1px solid #888;" + "border-radius:0.25em;" + "box-shadow: 0.8em 0.4em 0.4em black;" ); return ( "<div style='" + style + "'>" + this.inspect() + "</div>" ); }; peter;
Person named Peter