当我运行服务器时无法显示
/// Module dependencies.
var application_root = __dirname,
express = require("express"), //Web framework
path = require("path"), //Utilities for dealing with file paths
mongoose = require('mongoose'); //MongoDB integration
//Create server
var app = express.createServer();
// Configure server
app.configure(function () {
app.use(express.bodyParser()); //parses request body and populates req.body
app.use(express.methodOverride()); //checks req.body for HTTP method overrides
app.use(app.router); //perform route lookup based on url and HTTP method
app.use(express.static(path.join(application_root, "public"))); //Where to serve static content
app.use(express.errorHandler({ dumpExceptions:true, showStack:true })); //Show all errors in development
});
//Start server
app.listen(4711, function () {
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
答案 0 :(得分:1)
您需要在公共内部使用index.html来提供网站网址。此外,如果您在静态之前使用路由(app.router)。确保它不使用'/'路线。首先你会看到那一个。
答案 1 :(得分:0)
首先创建一个名为public
的文件夹,然后在里面创建一个名为index.html
的文件。
你的最后一部分应该是这样的:
//Start server
let listener = app.listen(4711, function () {
console.log("Express server listening on port %d in %s mode", listener.address().port, app.settings.env);
});
否则,您会收到app.address().port
为undefined
的错误消息。