当前位置:网站首页>1-11 创建线上文件服务
1-11 创建线上文件服务
2022-06-30 21:26:00 【画不完的饼】
创建线上文件服务
const http = require('http')
//创建web服务器
const server = http.createServer()
//监听web服务器request事件
server.on('request', (req, res) => {
const url = req.url
//把请求的url地址,映射为本地文件的存放路径
// const fpath = path.join(__dirname, url)
let fpath = ''
if (url == '/') {
fpath = path.join(__dirname, './clock/index1.html')
} else {
fpath = path.join(__dirname, './clock', url)
}
fs.readFile(fpath, 'utf-8', function(err, data) {
if (err) return res.end('404 not found')
res.end(data)
})
})
//启动服务器
server.listen(80, () => {
console.log('server running at http://127.0.0.1')
})
边栏推荐
- 银行集体下架的智能投顾产品,为何成了“鸡肋”?
- 《ClickHouse原理解析与应用实践》读书笔记(3)
- To the Sultanate of Anderson
- [grade evaluator] how to register a grade evaluator? How many passes?
- 一文读懂什么是MySQL索引下推(ICP)
- ca i啊几次哦啊句iu家哦11111
- Use the log server to output the topn of various Apache logs
- Radar data processing technology
- Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
- It is urgent for enterprises to protect API security
猜你喜欢

ICML2022 | 序列决策的效用理论

AKK菌——下一代有益菌

本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置

Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本

Reading notes of Clickhouse principle analysis and Application Practice (3)

asp.net core JWT传递

Text recognition svtr paper interpretation

用yml文件进行conda迁移环境时的报错小结

《ClickHouse原理解析与应用实践》读书笔记(1)

Ten security measures against unauthorized access attacks
随机推荐
SQL server extracts pure numbers from strings
Sqlserver string type converted to decimal or integer type
CA I ah, several times Oh, ah, a sentence IU home Oh
介绍一款|用于多组学整合和网络可视化分析的在线平台
Zaah Sultan looks at the old driver
Reading notes of Clickhouse principle analysis and Application Practice (3)
k个一组反转链表
侧睡哈哈哈哈
WebRTC系列-网络传输之本地scoket端口
用yml文件进行conda迁移环境时的报错小结
What about degradation of text generation model? Simctg tells you the answer
MySQL batch update
Adobe Photoshop (PS) - script development - remove file bloated script
笔记【JUC包以及Future介绍】
Encryption and decryption and the application of OpenSSL
布隆过滤器
攻防演练中的防泄露全家福
【无标题】
文本生成模型退化怎麼辦?SimCTG 告訴你答案
申请Vector 总线协议彩图壁纸挂画,非常棒哦!