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 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;
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.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/
2.6s
Install Node.js.
mkdir -p /opt/nodejs
cd /opt/nodejs
tar -Jxf node-v14.17.5-linux-x64.tar.xz
ln -s node-v${NODEJS_VERSION}-linux-x64/ default
3.2s
Install Yarn.
cd /opt
tar -zxf yarn-v1.22.5.tar.gz
ln -s yarn-${YARN_VERSION} yarn
0.6s
Configure npm
.
npm config set python /usr/bin/python3
npm config set unsafe-perm true # required because we are root
1.1s
Install IJavascript.
npm install -g ijavascript
ijsinstall --install=global
74.4s
Rename kernel so it doesn't conflict with browser-side JS cells.
cd /usr/local/share/jupyter/kernels
mv javascript nodejs
cd nodejs
sed -i 's/"display_name":.*Javascript (Node.js)"/"display_name":"Node.js"/
s/"language":.*javascript"/"language":"nodejs"/' kernel.json
0.6s
Get some other packages.
npm install -g plotly.js
npm install -g plotta.js
28.6s
Check.
du -hsx /
npm version
node -v
jupyter kernelspec list
3.3s
Add ngrok
curl -sS https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip
unzip /ngrok.zip
2.4s
Test
"use strict";
$$.async();
{
let console = global.console;
let $$ = global.$$;
setTimeout(function() {
console.log("Hello, world!");
$$.sendResult("Bye!");
}, 1000);
}
1.3s