Start here ยท How-to

Using the JavaScript Playground

The playground/ folder is a ready-made Node project for practising: type the examples, solve the exercises, run them with node, and test them with node --test. This page shows how to set it up once and how to work in it every day.

You will learn

  • What the playground contains and why it uses ES modules.
  • How to install Node 26, open the folder, and run files.
  • The everyday loop: create, run, experiment in the REPL, test.
  • Which chapter adds which files, and how they lead to the Chapter 16 project.
  • How to compare with the reference solution and fix common problems.

What is the playground?

A small Node project, published as its own repository on GitHub: coder-hop/js-book-playground. Your copy is the playground/ folder:

Because package.json says "type": "module", every .js file you create is an ES module: import/export and top-level await work, and strict mode is on (Chapters 1 and 14). Nothing needs npm install; every exercise uses only built-in features.

One-time setup

1. Get the playground

Clone the repository (or use Code โ†’ Download ZIP on the repository page):

The final playground argument names the folder playground/, so every path in this book (playground/hello.js, playground/reference/) matches your copy exactly.

2. Install Node 26 (LTS)

Get it from nodejs.org or a version manager (fnm install 26; see Appendix B). Node 24 works for almost everything, but Temporal and a few ES2025/2026 features need 26.

3. Open the folder

4. Check that it works

The everyday loop

  1. Create the file the exercise names, such as types.js.
  2. Run it: node types.js. Use node --watch types.js to re-run on every save.
  3. Experiment in the REPL. Start node in the playground folder and import your module dynamically:
  1. Compare with the exercise's Show solution only after you have something running. Different-but-working is fine; read the "why" note.
  2. Test anything you'll reuse. A file named something.test.js is picked up by npm test:

๐Ÿ’ก Read errors from the top line and the first stack frame in your file. Node prints the error type and message first, then the stack, so look for your file name in the stack lines.

What each chapter adds

ChapterFiles you create in playground/
1hello.js, features.js, env-report.js
2types.js, inventory.js
3errors.js, checkout.js
4ids.js, rate-limit.js
5settings.js, update.js
6format.js, receipt.js
7parse-orders.js, validate.js
8catalog.js, sales.js
9inventory-map.js, recommend.js
10diff.js, model.js
11models.js (Book, OutOfStockError) โ†ป, events.js
12payments.js โ†ป, queue.js
13stream-orders.js, pipeline.js
14money.js, main.js, lib/index.js (a barrel), plugins
15audit.js, transaction.js
16the order processor: src/, data/, test/ (โ†ป = reused here)
Bmoney.test.js, word-count/

If the folder gets crowded, create one sub-folder per chapter (ch02/types.js). Imports are relative (./, ../), so moving files only means updating those paths.

Using the reference project

Read its src/ files alongside Chapter 16. To compare your version: diff -ru reference/src src, or code --diff reference/src/processor.js src/processor.js.

Troubleshooting

SymptomLikely causeFix
No playground/ folder on your machineyou are reading the book onlinegit clone https://github.com/coder-hop/js-book-playground.git playground
SyntaxError: Cannot use import statement outside a modulethe file isn't treated as ESMrun it from playground/ (where package.json is), or rename it .mjs
ERR_MODULE_NOT_FOUND for ./moneya missing file extensionimport ./money.js
ReferenceError: require is not definedCommonJS syntax in an ES moduleuse import (Chapter 14)
TypeError: โ€ฆ is not a function for Object.groupBy, using syntax errors, Temporal is not definedNode is too oldnode --version; install 26 LTS
The program exits silently halfwayan unawaited promise, or a forEach(async โ€ฆ)await it, or use Promise.all (Chapter 12)
The process never exitsan active setInterval or open handleclear it, or use using (Chapter 15)
this is undefined in a callbacka detached methodan arrow function or bind (Chapter 4)

Recap

  • playground/ is an ESM Node project with npm start/npm test; reference/ is the finished Chapter 16 project.
  • Install Node 26 LTS, open the folder, and run files with node file.js (or --watch).
  • Experiment in the REPL with await import("./file.js"); test with *.test.js and node --test.
  • Always include .js in relative imports, and run commands from the playground folder.

Official docs