扫码关注官方订阅号
初学者,如何用node在项目下打开index.html?
欢迎选择我的课程,让我们一起见证您的进步~~
使用node.js的文件系统读取html的内容再使用response.sendFile对请求进行相应.
var fs = require('fs'); response.sendFile(fs.readFileSync('index.html','UTF-8'));
response可以直接用sendFile方法发文件出去
读取index.html 文件然后返回或者直接sendFile
fs.createReadStream(`${__dirname}/index.html`).pipe(response)
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用node.js的文件系统读取html的内容再使用response.sendFile对请求进行相应.
response可以直接用sendFile方法发文件出去
读取index.html 文件然后返回或者直接sendFile