如何更改Vash的默认文件扩展名?我想在Visual Studio 2015中使用语法高亮显示,因此我想将扩展名从.vash更改为.html。
我读到我应该可以做类似的事情:
app.engine("html", require("vash").__express);
但是我无法弄清楚语法,或者我的命令顺序错误。
我的代码使用.vash文件,但是如果我尝试更改为.html,则会出现以下错误。我已确认该文件夹中确实存在index.html文件。
无法查找视图"索引"在views目录中IQuestions.FrontEnd \ views"
var http = require("http");
var express = require("express");
var path = require("path");
var logger = require("morgan");
var cookieParser = require("cookie-parser");
var bodyParser = require("body-parser");
var routes = require("./routes/index");
var users = require("./routes/users");
var app = express();
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.engine("html", require("vash").__express);
app.set("view engine", "vash");
app.set("port", process.env.PORT || 3000);
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require("stylus").middleware(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, "public")));
app.use("/", routes);
app.use("/users", users);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error("Not Found");
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get("env") === "development") {
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render("error", {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render("error", {
message: err.message,
error: {}
});
});
module.exports = app;
http.createServer(app).listen(app.get("port"), function () {
console.log("Express server listening on port " + app.get("port"));
});
答案 0 :(得分:0)
试试这个
app.set('view engine', 'html');
app.engine("html", require('vash').__express);