Reference: https://hoofoo.me/article/2017-04-11/%E8%B5%9B%E7%A0%81%E7%BD%91%E5%89%8D%E7%AB%AF%E7%AC%94%E8%AF%95%E6%9C% Ac%e5%9c%b0%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba.html
Implementation of the Print method
This is no difficulty, just console.log
change the name of the thing, a line of code can be solved.
var print = Console.log
implementation of Read_line method
As we Node.js
all know, it is an asynchronous language, so it is readline
also an asynchronous operation, according to the node. JS Chinese documentation, readline
this is done:
Const ReadLine = require (' readline '= readline.createinterface ({ Input:process.stdin, output: Process.stdout}); Rl.question (' What do you think of the node. JS Chinese web? ', (answer) = { // to process the answer console.log (' Thank you for your feedback: ${answer} '); Rl.close ();});
or it is done in the following way:
Rl.on (' line ', (input) = { Console.log (' Received: ${input} ');});
installation readline-sync
, Node.js
environment, I will not introduce a lot of the big boys are very clear. Yes, if it cli
is useful to write a tool, but now the needs are different, we need to copy to the answer box can be directly run code, now the artifact should appear.
NPM Install Readline-sync
Despair is still GitHub
reliable, only two steps to achieve the read_line
method:
var __readline = require (' Readline-sync '})var read_line = __ Readline.prompt
Before writing, copy the following code to the previous
"JavaScript" Code network front-end written test local environment construction