Over a million developers have joined DZone.

Combining Code Editing With a Command Line

DZone's Guide to

Combining Code Editing With a Command Line

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

Currently, you are forced to work with JavaScript code in either of two modes: You can either use a code editor and edit multiple lines or you can use an interactive command line and work with one line at a time (editing, evaluating). With jsrepl [ GitHub project, live demo], I have prototyped a combination of both modes – no need to chose, any more.

The name is derived from the abbreviation REPL (read-eval-print loop) that is a common synonym for “command line” in the functional world. Node.js uses that term, too [1].

How does jsrepl work?

It is used like a normal text editor, so the Return key inserts line breaks. If you want to evaluate expressions or statements, you have two options:
  • Multi-line evaluation: select text and hit Shift-Return.
  • Single-line evaluation: place the cursor in the line you want to evaluate and hit Shift-Return.
The result of such evaluations is inserted at the end of the text buffer. console.log output goes there, too. I had to use hacks to make var declarations and function declarations work, so your mileage may vary. I will continue to tweak jsrepl, to explore this design space, but probably won’t turn it into a full-blown tool. For example, output and results could be inserted where the cursor currently is. That would work better for long text buffers, but is less clean and might mess up the content.

Prior art

jsrepl has been inspired by the Macintosh Programmer’s Workshop, which I have never used, but read about a long time ago (mid 1980s). There must be other prior art, too (Smalltalk, Lisp, ...).



  1. Execute code each time the Node.js REPL starts

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.


Published at DZone with permission of Axel Rauschmayer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}