我正在做一个简单的节点项目来练习,但是我不能用它的css样式来服务html文件。
我相信它以前在相同的代码下工作得很好,但现在我不明白为什么它不能运行。我对它进行了搜索,并复制了一些替换目录名称的代码,但这并没有改变任何东西。这是我的代码。我还尝试使用path模块来连接文件名和目录名。
app.use(express.static('public'));
app.get('/', (req, res)=>{
res.send("Welcome to our website");
});
app.get("/signup", (req, res)=>{
res.sendFile(__dirname + "/index.html");
});
//My directory:
testapp1
--node_modules
--public
--styles.css
--index.html
--app.js
--package.json
--package-lock.json在开发人员控制台的网络选项卡中,显示:状态:已取消类型:样式表启动器: index.html大小: 0B时间: 29ms瀑布:“无”
发布于 2019-02-17 06:38:28
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function (req, res, next) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});试一试吧。
https://stackoverflow.com/questions/54728015
复制相似问题