同步&异步
node核心模块
注意:使用前需要先导入核心模块
其中,内置API模块为:http fs path
完整的URL路径为:协议+IP/域名+端口号+路由+?+参数信息
fs
导入:const fs=require(“fs”);
http
导入:const http = require(‘http’);
const http = require('http');
const fs = require('fs');
const server = http.createServer((req, res) => {
if (req.url === '/myapp/index.html' || req.url === "/") {
//当前文件所在文件夹的绝对路径
fs.readFile(__dirname+"/myapp/index.html",(err,data)=>{
if(err) throw err;
res.end(data);
})
}else{
res.end('');
}
})
server.listen(8080, () => {
console.log('http is xxxx');
})
path
导入:const path =require(‘path’);