如何将多个文件和文件夹发送到本地服务器Express

发布于 2025-01-30 10:34:04 字数 700 浏览 1 评论 0原文

我的项目在下面的屏幕截图中包含文件。我的任务是在本地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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文