Nodebooks: Introducing Node.js Data Science Notebooks

Python and Node.js in the same Jupyter notebook (part 1)

I am a developer, as in computer code. My job is to persuade computers to do my bidding by typing gibberish into a text file and presenting its contents to the computer like a sacrificial oblation.

The contents of the text files have changed over the years as my computer and I have communicated in several languages: BASIC, Pascal, C, C++, Forth, Java, Objective-C, PHP, Python. But the language we share most often these days is JavaScript, either inside web pages or to run server-side apps and command-line tools using Node.js.

If I had a gun to my head and had to program my way out of it (which is, let’s face it, unlikely), I’d choose Node.js. It’s the language I have to Google least to remember the syntax.

Editor’s note: Parts 1, 2, and 3 published in fall 2017. A more recent 2018 article updates the variable-sharing features described in part 2 of this series:

Notebooks

Notebooks (that’s Jupyter/IPython Notebooks, not Moleskine® notebooks) are where data scientists process, analyse, and visualise data in an iterative, collaborative environment. Like other developers, I am not a data scientist, but I do like the idea of having a scratchpad where I can write some code, iteratively work on some algorithms, and visualise the results quickly.

To that end, David Taieb and I created pixiedust_node, an add-on for Jupyter notebooks that allows Node.js/JavaScript to run inside notebook cells. It’s built on the popular PixieDust helper library. So let’s get started!

Installing

Install both pixiedust and pixiedust_node using pip, the Python package manager. In a Jupyter Notebook cell:

!pip install pixiedust

!pip install pixiedust_node

Using pixiedust_node

Now we can import pixiedust_node into our notebook:

import pixiedust_node

And then we can write JavaScript code in cells whose first line is %%node :