ノードのビット

#### fs.readFile(path [、options]、callback)

ファイルの読み取り

const fs =require('fs')

// console.log(1)

// fs.readFile('./box.txt','utf8',(err,date)=>{
//     // nodejs是以错误优先 所以err先抛错
//     if(err) throw(err)
//     // console.log(date.toString())//tosting将流转化成字符串
//     console.log(date )//设置了编码就不用转字符串
//     // console.log(2)
// })

// console.log(3)// 输出结果是132   它是异步的  异步的阻塞操作会进入事件队列

   var date=fs.readFileSync('./box.txt','utf8')
   console.log(date)

//    她是同步的 所以不设置回调函数

http.createServer([options] [、requestListener])

httpサービスを作成する

 const http = require('http')//用来发请求或是创建服务
 const path= require('path')//z只要用到路径先引入path
 let port=8888;//端口号
//  createServer创建服务
 let server=http.createServer((req,res)=>{
    //  req请求
    //  res响应
    res.writeHead(200, {
       
        'Content-Type': 'text/html;charset=utf-8;'
      })
      res.write(`<h1>x响应的成功<h1/>`)
      res.end()//结束响应
 })
//  开启端口监听
server.listen(port,()=>{
    console.log( `server is running on http://localhost:${port}`)
})

モジュールの同期は同期していますが、非同期ではありません

おすすめ

転載: blog.csdn.net/weixin_45663264/article/details/102690344