help
help copied to clipboard
Disable Preview on REPL when used on the command line by calling nodejs
Details
Is there a way to disable the preview when calling nodejs and showing the REPL.
I am using the Read Evaluation Print Loop (REPL) to teach my students about JavaScript. I like to use REPL to pose questions and explore what the answers might be. However, the preview function of REPL steels my thunder and means I cannot use it to experiment and ask questions during a programming lecture. For example if I type null == false, it then shows the answer before I can ask a student what it evaluates to. It did not used to do this and so I'd like to turn it off. I could not find any information in your documentation about this, or no commends in the help options of REPL.
Node.js version
12.22.12
Example code
No response
Operating system
Linux bash terminal.
Scope
Runtime.
Module and version
REPL.
Before getting into the details, I would recommend updating to the latest LTS release of Node.js as the v12 releases are pretty old and are no longer supported, they've reached their EoL (End-of-Life) phase, you can install the latest LTS release of Node.js from the official Node.js website.
The default REPL initializer when running node without any arguments is mostly only initialized/started with the default REPL options and can't be changed through the CLI (Command-Line Interface).
Although you can absolutely start your own REPL instance with customized behavior using the built-in repl module. You can set the preview option of the repl.start() method to false to disable the previews from the REPL.
For example:
Put this code snippet into a file (I'm gonna name it custom-repl.mjs for the sake of the example, but you can name it whatever you want):
import repl from 'node:repl';
repl.start({ preview: false });
(Note: the import statements can only be used in ES modules since the file with the .mjs file extension is an ES module, if you want to use CommonJS then name the file as custom-repl.js and replace import repl from 'node:repl'; with const repl = require('node:repl');.)
And run the file with Node.js to start a REPL without the previews:
$ node custom-repl.mjs
(If you've named it as custom-repl.js then run node custom-repl.js instead.)
And voila! You've got a REPL with no previews.
I believe that version of node is what comes from the package manager on our Debian stable server that our students SSH into and share. It works for us, and generally we do not like to change packages mid semester just in case it gives problems with anyone's course notes and project descriptions, but we will consider this for December.
Thanks for the work around. It did not work for me. I still got the preview.
I would like to suggest that a new command be added into the commands inside REPL, such as .preview on, .preview off. That would be simple but very effective.
Thanks for the work around. It did not work for me. I still got the preview.
May you show us the way you're doing it? Such as the contents of the file you've put that code snippet into.
I would like to suggest that a new command be added into the commands inside REPL, such as .preview on, .preview off. That would be simple but very effective.
I would recommend opening an issue at the Node.js repository with the Feature request template (click here to do so), that way others who work on the REPL side can weigh in their opinions on it and eventually make it a new command after it's accepted.
There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment.
Closing after no activity on this issue for 12 months.