David Schmudde / Aug 18 2021
Remix of Node.js Environment by
Nextjournal
The Node.js Environment
Including ngrok
This environment uses the IJavascript kernel and runs Node.js v14.17.5, with npm v6.14.14 and Yarn v1.22.5 for package management.
Showcase
function Person(name) { this.name = name;}var peter = new Person("Peter");var util = require("util");console.log(util.inspect(peter)); // shown on stdoutpeter; // shown as an execution resultPerson.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;0.4s
Setup
Build the node environment
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.txtwget --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 --importwget --progress=dot:giga ${FILEURL} ${FILEURL}.ascgpg --verify ${FILENAME}.asccp $FILENAME /results/2.6s
Install Node.js.
mkdir -p /opt/nodejscd /opt/nodejstar -Jxf node-v14.17.5-linux-x64.tar.xzln -s node-v${NODEJS_VERSION}-linux-x64/ default3.2s
Install Yarn.
cd /opttar -zxf yarn-v1.22.5.tar.gzln -s yarn-${YARN_VERSION} yarn0.6s
Configure npm.
npm config set python /usr/bin/python3npm config set unsafe-perm true # required because we are root1.1s
Install IJavascript.
npm install -g ijavascriptijsinstall --install=global74.4s
Rename kernel so it doesn't conflict with browser-side JS cells.
cd /usr/local/share/jupyter/kernelsmv javascript nodejscd nodejssed -i 's/"display_name":.*Javascript (Node.js)"/"display_name":"Node.js"/s/"language":.*javascript"/"language":"nodejs"/' kernel.json0.6s
Get some other packages.
npm install -g plotly.jsnpm install -g plotta.js28.6s
Check.
du -hsx /npm versionnode -vjupyter kernelspec list3.3s
Add ngrok
curl -sS https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zipunzip /ngrok.zip2.4s
Test
"use strict";$$.async();{ let console = global.console; let $$ = global.$$; setTimeout(function() { console.log("Hello, world!"); $$.sendResult("Bye!"); }, 1000);}1.3s