node.js - 此节点js代码输出两个控制台日志,我不明白为什么
问题描述
这段代码有一个console.log
输出两次的语句,我不明白为什么。有谁知道为什么会这样?
const http = require("http");
const fs = require("fs");
const _ = require("lodash");
const server = http.createServer((req, res) => {
console.log("hey there"); //this outputs two times in the console for a request
res.setHeader("Content-Type", "text/html");
fs.readFile("./views/index.html", (err, data) => {
if (err) {
console.log("error");
res.end();
} else {
res.end(data);
}
});
});
server.listen(3000, "localhost", () => {
console.log("this is up and running in port 3000");
});
解决方案
推荐阅读
- android - 将配置添加为依赖项是一种令人困惑的行为,不建议这样做
- string - 打字稿:如何在接口中的字符串索引签名定义中引用属性名称
- python - 熊猫将时间序列数据列转换为列表列?
- excel - 插入、复制、删除麻烦
- ceph - ceph mds错误目录inode上的错误回溯并写入新文件崩溃
- python-3.x - 用漂亮的汤提取额外的数据
- swiftui - 使用 ForEach 创建视图,但如何让 onTapGesture 立即更新?
- java - 使用 Javax servlet Webfilter 在 Spring Boot 中 CORS 起源不起作用
- javascript - 如何区分同一个git仓库下不同文件夹的变化?
- javascript - 如果没有像 Apollo 或 Relay 这样的库,浏览器客户端如何使用 GraphQL 订阅?