标签:资源 serve bsp create code localhost read htm oca
//导入http模块
let http = require(‘http‘)
//导入url模块 let url = require(‘url‘)
//导入文件系统模块 let fs = require(‘fs‘)
//创建http服务并且监听3000端口 let service = http.createServer((req,res) =>{
//拉取url里的资源请求地址 let pathname = url.parse(req.url).pathname
//读取该地址下的资源 fs.readFile(pathname.substring(1),(err,data) => { if (err){ res.statusCode = 404 res.setHeader(‘Content-Type‘,‘text/html;charset=uft-8‘) }else{ res.statusCode = 200 res.setHeader(‘Content-Type‘,‘text/html;charset=uft-8‘) res.write(data.toString()) } res.end() }) }).listen(3000,‘localhost‘)
标签:资源 serve bsp create code localhost read htm oca
原文地址:http://www.cnblogs.com/zhouxiaohouer/p/7912506.html