javascript - 在nodejs的程序里面怎么理解IO呢,如何用一段代码来说明IO
阿神
阿神 2017-04-17 16:37:27
0
4
586
阿神
阿神

闭关修行中......

reply all(4)
左手右手慢动作

You may not have described the problem clearly. IO is just a vocabulary, and HTML is also an abbreviation.
Do you want to ask: What is asynchronous IO in nodejs?

Ty80

IO is the abbreviation of Input/Output. Common inputs include console (keyboard) input and file output; common outputs include console (monitor) output and file output - these are concepts that have existed for a long time. Now IO also includes network IO, device IO... As long as it is input and output, it can be called IO.

The code you gave is just an example of reading a file in IO, that is, inputting from a file. Compared with common file reading operations in other languages ​​or environments, the special point here is that it is asynchronous. When initiating a file reading request (fs.readFile)的同时,传递了一个回调((err, data) => {...})作为参数进去,要求读取文件完成之后由IO库调用这个回调,把文件内容(data), it is passed as a parameter to the callback function so that the callback function can process it. The processing process, that is, the callback function, is already defined when the request to read the file is initiated.

I guess you are not very clear about the concept of asynchronous, but if you talk about it here and you can’t explain it clearly in a few words, I suggest you search for relevant information to take a look. Just search for “JavaScript asynchronous”

刘奇

fs.readFile is the operation of reading a file, which is equivalent to what you said I,读取的文件数据存储在data变量里面;fs.writeFile是写文件的操作(你代码里面没有涉及),相当于你说O,输出数据到一个外部文件。简单的说:I是从外部读入数据到程序,O is outputting data from the program to an external file. (Old man, I’m heartbroken! You must tell me the reason why you stepped on me)

左手右手慢动作

I/O stream, i.e. input and output, reading and writing files means inputting and outputting data

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template