【发布时间】:2016-09-17 15:34:17
【问题描述】:
var express = require('express'),
app = express(),
db = require('./db'),
bodyParser = require('body-parser'),
controller = require('./controller');
app.use(express.static('../public'));
app.get('/server', function (req, res) {
console.log(__dirname);
res.sendFile('/../client/index.html');
});
我已经设置了这个快速服务器,但是使用上面的代码,当我查看 localhost:portnumber 时,我得到“Cannot GET /”。如果我将 GET 方法更改为:
app.get('/', function(req, res) {
res.sendFile(__dirname + '../client/index.html');
});
我得到“'C:\Users\TC\Documents\Desktop\myapp\multiplayerWebSite\server..\client\index.html' at Error (native)”,如果我将其更改为:
app.get('/', function(req, res) {
res.sendFile('../client/index.html');
});
我收到“TypeError:路径必须是绝对路径或指定 res.sendFile 的根目录” 错误:ENOENT:没有这样的文件或目录
当我在根目录中拥有所有内容时,服务器运行良好,但我想更改文件夹结构以使其更加整洁/专业。如果有人能告诉我我做错了什么,我将不胜感激。提前谢谢!
【问题讨论】:
标签: javascript node.js express