Node.js Environment

Default environment for Node.js

This notebook describes and creates the default Node.js environment in Nextjournal. Check out the showcase if you want to see what the environment contains. To see how it’s built, see setup.

Nextjournal's environment uses the IJavascript kernel and runs Node.js v12.13.1, with npm v6.12.1 and Yarn v1.21.1 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;
1.3s
Node Test (Node.js)
Node.js
Person named Peter

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/
3.5s
Node.js (Bash)
node-v12.13.1-linux-x64.tar.xz
yarn-v1.21.1.tar.gz

Install Node.js.

mkdir -p /opt/nodejs
cd /opt/nodejs
tar -Jxf NJ__REF_
ln -s node-v${NODEJS_VERSION}-linux-x64/ default
2.7s
Node.js (Bash)

Install Yarn.

cd /opt
tar -zxf NJ__REF_
ln -s yarn-${YARN_VERSION} yarn
0.6s
Node.js (Bash)

Configure npm.

npm config set python /usr/bin/python3
npm config set unsafe-perm true # required because we are root
0.8s
Node.js (Bash)

Install IJavascript.

npm install -g ijavascript
ijsinstall --install=global
7.3s
Node.js (Bash)

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.1s
Node.js (Bash)

Get some other packages.

npm install -g plotly.js
npm install -g plotta.js
34.2s
Node.js (Bash)

Check.

du -hsx /
npm version
node -v
jupyter kernelspec list
2.4s
Node.js (Bash)

Test

"use strict";
$$.async();
{
    let console = global.console;
    let $$ = global.$$;
    setTimeout(function() {
        console.log("Hello, world!");
        $$.sendResult("Bye!");
    }, 1000);
}
1.4s
Node Test (Node.js)
Node.js
'Bye!'
Runtimes (2)
Runtime Languages (1)