如何将多行文本粘贴到nodejs REPL中,而不会发送垃圾邮件

我正在通过Linuxterminal使用nodejs REPL。 我有很大一部分代码要粘贴到nodejs中。 但是,粘贴代码会导致terminal在一段时间内不响应。 这是因为REPL用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 

这有点烦人。 我知道我可以通过将其粘贴到文件并将其加载到REPL中来解决它:

 .load some-file.js 

但是我想知道是否有办法通过单独粘贴来实现,而且我相信肯定有一个这样的时间和地点。

问题是你的代码使用缩进标签,而Node.js REPL将标签作为自动完成的提示。

要解决此问题,请使用忽略选项卡的.editor命令:

 $ 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是在Node.js v6.4.0中添加的一个function,所以如果你碰巧使用的是比这个版本更早的版本,那么你运气不好。

查看Node.js文档以获取关于这些特殊REPL命令的更多信息。

只要把双引号放在一切

 "aaa bbb ccc ddd" 

并粘贴包括这些报价