![](/img/trans.png)
[英]I am new to node js , I want to route a page from html file but its not working--- Node js routing problem
[英]want to run my html page on local server using node when i am loading the page but the css file is not working
我的文件夹结构。
下面是我的 server.js 文件
var express = require("express");
var path = require("path");
var app= express();
var port = 8080;
app.use("/" , function(req,res){
res.sendFile(path.join(__dirname + "/webForm.html"));
});
app.use('/assets', express.static(__dirname + '/public'));
app.listen(port);
在我引用了 css 文件的 webForm.html 文件下方
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Basic Details</title>
<link rel="stylesheet" href="/assets/form.css">
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
请看我在我的 package.json 文件中犯了什么错误
{
"name": "ex-website",
"version": "1.0.0",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1"
},
"main": "server.js",
"devDependencies": {},
"author": "",
"license": "ISC",
"description": ""
}
你试过“。”吗?
href="./assets/form.css"
这应该足够了。
app.use('/assets', express.static('public'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.