Using JavaScript and TypeScript in jupyter notebook

Posted on 2025-05-23 in Trucs et astuces

While wandering how to run some tests with JavaScript, I discorvered that deno, a JavaScript runtime like NodeJS, has support for jupyter notebooks thanks to this article. It works perfectly. Install deno (probably available in your distribution repositories), run deno jupyter --install and you are good to go!

To get a package from npm, prefix its name with npm: like this: import _ from 'npm:lodash'. You can then use it normally:

import _ from 'npm:lodash'
_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });

It even supports TypeScript code out of the box:

const test: string[] = [];
const myPush = <T>(array: T[], elt:T) => {
    array.push(elt);
};
myPush(test, 12);
console.log(test);

Neat isn’t it?