HazelJS Notebook Package
@hazeljs/notebook runs TypeScript notebooks in a local browser workspace powered by Node.js. Use it to explore data, inspect results as tables, and save the code and steps as a reusable notebook.
Quick Reference
- Requirements — Node.js 20 or later.
- CLI —
hazel-notebook [notebook.hnb.json] [--port 4321]. - Output — Use
display(value)orconsole.table(value)for tabular results andconsole.log()for text. - Save and share — Export an
.hnb.jsonfile to reopen it later or share it with a teammate.
Install and start
In your project, install Notebook and launch it from the project directory.
npm install --save-dev @hazeljs/notebook
npx hazel-notebook
Open the local URL printed in your terminal. To reopen an exported notebook or choose another port, pass the file path and --port.
npx hazel-notebook ./analysis.hnb.json --port 4322
Run your first cell
Paste this code into a cell and select Run all.
const sales = [
{ store: 'Stockholm', orders: 12 },
{ store: 'Malmö', orders: 8 },
];
display(sales);
console.log(sales.reduce((total, row) => total + row.orders, 0));
The cell displays a table and prints a total of 20. Table controls let you page through results and download the available rows as CSV.
Run all executes cells in order. Run through (Shift+Enter) reruns every cell from the start through the selected cell. Cells share variables and imports within a run, so earlier cells may repeat side effects. Top-level await is supported. The runner transpiles TypeScript without type-checking it.
Save and reopen notebooks
Edits are saved in the current browser for that notebook and port. Use Export to download the notebook as an .hnb.json file. Imports and relative paths resolve from the notebook file's directory, or from the directory where you started the CLI for a blank notebook.
The server listens on the loopback interface. Each run starts a Node.js process with access to local files, environment variables, and the network. Run notebook code you trust.
Try the Frame notebook
From the root of a HazelJS source checkout, install the workspace dependencies, build Frame, and start the included notebook.
npm ci
npm run build --workspace=@hazeljs/frame
npm --prefix benchmarks/frame run notebook:ui
Open the printed URL and select Run all to preview a fictional student roster, rank exam scores, and compare class averages. The demo uses Frame to query a CSV file.