使用node.js实现apache功能
2021-04-30 05:29
阅读:555
标签:url 使用 == OLE ons lis nod read des
先实现在url中输入文件路径能展示对应文件内容功能
const http = require(‘http‘) const fs = require(‘fs‘) const server = http.createServer() const wwwDir = ‘/Users/lianglanlan/Desktop/code/study/node/www‘ server.on(‘request‘, (req, res) => { const url = req.url let filePath = ‘/index.html‘ if (url !== ‘/‘) { filePath = url } fs.readFile(wwwDir + filePath, (err, data) => { if (err) { console.log(err) return res.end(‘404 Not Found‘) } res.end(data) }) }) server.listen(3010, () => { console.log(‘running...‘) })
使用node.js实现apache功能
标签:url 使用 == OLE ons lis nod read des
原文地址:https://www.cnblogs.com/lianglanlan/p/12196099.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:使用node.js实现apache功能
文章链接:http://soscw.com/index.php/essay/80288.html
文章标题:使用node.js实现apache功能
文章链接:http://soscw.com/index.php/essay/80288.html
评论
亲,登录后才可以留言!