如何将多个文件和文件夹发送到本地服务器Express
我的项目在下面的屏幕截图中包含文件。我的任务是在本地Express服务器上运行整个项目。但是只显示没有样式的index.html。静态文件方法也不起作用。我该如何解决? ScreenShot
server.js代码:
const express = require("express");
const app = express();
var http = require('http').Server(app);
app.use(express.static(__dirname + 'css'))
app.use(express.static(__dirname + 'img'))
app.use(express.static(__dirname + 'js'))
app.use(express.static(__dirname + 'sass'))
app.use(express.static(__dirname + 'vendor'))
app.get('/', function(req, res){
res.sendfile('index.html');
});
http.listen(3000, function(){
console.log('listening on 3000');
});
My project has files, in the screenshot below. My task is to run the whole project on a local express server. But only index.html is displayed without styles. The static file method doesn't work either. How can I fix this?
screenshot
server.js code:
const express = require("express");
const app = express();
var http = require('http').Server(app);
app.use(express.static(__dirname + 'css'))
app.use(express.static(__dirname + 'img'))
app.use(express.static(__dirname + 'js'))
app.use(express.static(__dirname + 'sass'))
app.use(express.static(__dirname + 'vendor'))
app.get('/', function(req, res){
res.sendfile('index.html');
});
http.listen(3000, function(){
console.log('listening on 3000');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论