Zero-config REPL for experimenting with next-generation JavaScript.
It automatically compiles and re-runs your script every time you save. Think of it as a JSBin-like setup for your local editor and terminal – with full access to Node APIs and modules.
As well as for experimenting, esbox may be useful in situations like workshops and screencasts – it makes it easy to do live code demos in ES2016 and beyond, without getting bogged down in build systems.
> npm install -g esboxTo run script.js in a box:
> esbox script.jsEvery time you save the file, esbox clears the terminal display and runs your script again. Any uncaught errors get pretty-printed for easy debugging.
For more options, see esbox --help.
You can use any proposed ECMAScript features that Babel supports (stage-0 and above), including async/await, destructuring, rest/spread, etc.
For a number of popular libraries, you can just import them without the need to install them first.
This includes lodash, bluebird, chalk, chai, express, request – and anything else listed under dependencies in esbox's own package.json.
This is made possible by rewiring require() to use esbox's own node_modules folder as an extra possible module source. (Your own locally installed modules still take precedence if found.)
For example, a script like this just works in esbox:
import cheerio from 'cheerio';
import fetch from 'isomorphic-fetch';
import { cyan } from 'chalk';
(async () => {
const result = await fetch('https://www.nytimes.com');
console.assert(result.ok);
const $ = cheerio.load(await result.text());
console.log('The New York Times headlines:');
$('.story-heading').each((i, element) => {
console.log(' ', cyan($(element).text().trim()));
});
})();