我如何在节点js服务器中包含CSS js
var http = require("http");
var fs = require("fs");
var todo = http.createServer(function(req, res) {
fs.readFile("./todo.html", function(err, data) {
if (err) {
console.log("no");
} else {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(data);
}
});
});
todo.listen(3000);
这是我的nodejs代码,我不知道如何包括css js文件。我不能只包含html文件。我想包含css js文件,因为我想通过nodejs构建网络应用]
回答如下:如果需要使用nodejs构建Web应用程序,建议使用诸如express.js
(https://expressjs/)之类的nodejs框架。这些已经具有启动和运行快速Web应用程序的基本构建块。请参考express.js文档,了解基本路由和提供静态文件以构建简单的Web应用程序。这些是一些入门指南
- https://expressjs/en/starter/static-files.html
- https://expressjs/en/starter/hello-world.html
我如何在节点js服务器中包含CSS js
var http = require("http");
var fs = require("fs");
var todo = http.createServer(function(req, res) {
fs.readFile("./todo.html", function(err, data) {
if (err) {
console.log("no");
} else {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(data);
}
});
});
todo.listen(3000);
这是我的nodejs代码,我不知道如何包括css js文件。我不能只包含html文件。我想包含css js文件,因为我想通过nodejs构建网络应用]
回答如下:如果需要使用nodejs构建Web应用程序,建议使用诸如express.js
(https://expressjs/)之类的nodejs框架。这些已经具有启动和运行快速Web应用程序的基本构建块。请参考express.js文档,了解基本路由和提供静态文件以构建简单的Web应用程序。这些是一些入门指南
- https://expressjs/en/starter/static-files.html
- https://expressjs/en/starter/hello-world.html