jrc03c
jrc03c

Reputation: 321

Disable Node REPL pre-evaluation?

In the Node (v16.7.0) REPL, Node tries to evaluate my statement before I've finished typing it. For example, if I type 2 + 2, it displays a faint 4 on the next line before I hit the Enter key. Is there a way to disable this behavior? For most cases, it's not a problem; but when I'm performing expensive operations, the REPL lags or freezes up as I'm trying to finish typing my statement. To be clear, the problem is not that the interpreter is printing the output; it's that it's trying to evaluate my statement before I finish typing it. Thanks in advance for your help!

Upvotes: 7

Views: 496

Answers (1)

paradoja
paradoja

Reputation: 3090

The REPL library calls that a preview (search for preview in the link for more info). I'm not aware how to launch the default node REPL with command line options (or some other kind of configuration options) so that previews are not shown, but the REPL itself is a library you can use, with all the defaults (or whatever you prefer) and removing previews - for this check the REPL library options.

A basic example is creating this script:

#!/usr/bin/env node

const repl = require('repl');

repl.start({
  preview: false
});

Make sure you also have it as executable (in Linux/Mac from the command line it would be with chmod +x name-of-repl-script from the terminal), and well, run that script instead of node directly. Alternatively you can run the script with node name-of-repl-script (here, assuming node is the NodeJS REPL executable and that it's in the path).

Upvotes: 6

Related Questions