node.js - 如何为我可以使用 node.js 在一个文件中更改的网站创建标题
问题描述
我正在尝试从视频中为我正在处理的网站创建一个 node.js 标头,但是无论视频声称多么简单,我都无法弄清楚我做错了什么
const http = require('http');
const fs = require("fs");
const port = 3000;
const server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' })
fs.readFile('Header.html', function(error, data) {
if(error) {
res.writeHead(404)
res.write('Error: Header not found')
} else {
res.write(data)
}
res.end()
})
})
server.listen(port, function(error) {
if(error) {
console.log("Something went wrong: " + error);
} else {
console.log("Server is up and running on port " + port);
}
})
解决方案
推荐阅读
- javascript - 如何使用 href 和 onclick 函数传递参数?
- javascript - 如何使用 import 导入 Socket.io - Nodejs
- javascript - 未捕获的 ReferenceError:firebase 未在 login.js:2 中定义
- liquibase - 需要步骤在 Spring Boot 中使用 docker 实现 liquibase 以及如何使用 docker 执行
- 3d - 没有法线的光线追踪阴影偏差
- angular - 如何从 ionic 5 电容器应用程序中的 url 下载文件
- android - 空闲和加载状态的单元测试失败
- kubernetes - kubernetes ingress-nginx:名称为 nginx 的 IngressClass 对 ingress-nginx 无效
- python - 如何通过查找值来查找列号
- javascript - 未捕获的类型错误:c.addEventListener 不是函数......?javascript DOM 事件