I'm working with the nodejs REPL through a Linux terminal. I have a large portion of code that I want to paste into nodejs. However, pasting the code causes the terminal to become non-responsive for a little while. This is because the REPL spits the following text with every line of the expression:
Array Boolean Date Error EvalError
Function Infinity JSON Math NaN
Number Object RangeError ReferenceError RegExp
String SyntaxError TypeError URIError decodeURI
decodeURIComponent encodeURI encodeURIComponent eval isFinite
isNaN parseFloat parseInt undefined
ArrayBuffer Buffer DataView FMM Float32Array
Float64Array GLOBAL Int16Array Int32Array Int8Array
Uint16Array Uint32Array Uint8Array Uint8ClampedArray _
assert buffer child_process clearImmediate clearInterval
clearTimeout cluster console crypto dgram
dns domain escape events fs
global http https module net
os path process punycode querystring
readline require root setImmediate setInterval
setTimeout stream string_decoder tls tty
unescape url util vm zlib
__defineGetter__ __defineSetter__ __lookupGetter__ __lookupSetter__ constructor
hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString
valueOf
This is kind of annoying. I know I can work around it by pasting it into a file and loading it into REPL:
.load some-file.js
But I want to know if there's a way to do it by pasting alone, and I'm sure there must be a time and place for this.
The problem is that your code uses tabs for indentation, while the Node.js REPL treats tabs as cues for autocompletion.
To fix this problem, use the .editor
command, which ignores tabs:
$ node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function a() {
console.log('hello world');
}
a();
// type ^D here
hello world
undefined
>
.editor
is a feature added in Node.js v6.4.0, so if you happen to be using a version older than that, you are out of luck.
Check out Node.js documentation for more information on these special REPL commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With