Home > Article > Web Front-end > Let’s briefly talk about streams in Node.js and talk about three ways to read files
This article will give you a brief understanding of the streams in Node.js, and introduce the three ways to read files: asynchronous reading of files, synchronous reading of files and streaming of reading files. .
Node.js
npm i 第三方模块
Custom module written by myself (write js file). [Recommended learning: "nodejs Tutorial"]
Asynchronously read the file (readFile )
To solve the problem, use promise
readFileSync
var nr = fs.readFileSync('./b.txt', 'utf-8') console.log(nr)
Copy small files first read and then copy copyFile.js
copybigFile.js
Module
createServer((req,res)=>{ // 设置一个响应头 : res.writeHead(200, {"Content-Type":"text/html;charset=utf-8"}); req.url // 获取客户端请求的网址 (除了 协议 端口 域名 之外的地址 http://www.baidu.com?main=22&pid=90) res.write(); // 响应用户的请求 res.end(); // 结束响应 }) get("url路径", 回调方法) // 方法 请求服务器数据
['1',',',',','2','3','9',',',','] Move the comma to the right
Programming Video! !
The above is the detailed content of Let’s briefly talk about streams in Node.js and talk about three ways to read files. For more information, please follow other related articles on the PHP Chinese website!