我的目录如下所示:
/config.json , /server.js , /staticFiles/welcome.html
运行 server.js 给出错误:
app.use(express.static(_dirname + "/staticFiles")); ^ ReferenceError: _dirname 未定义
我的 Server.js:
//------------Server-------------
var fs = require("fs");
var config = JSON.parse(fs.readFileSync("./config.json"));
console.log("Server UP and running..");
var host = config.host;
var port = config.port;
var express = require("express");
var app = express.createServer();
//---------Application----------------
app.use(app.router);
app.use(express.static(_dirname + "/staticFiles"));
app.get("/", function(request,response){
response.send("<h1>"/" of TrimServer</h1>");
});
app.listen(port,host);
console.log("Listening on Port -->",port);
//--------------End-------------------