Error: Failed to lookup view "app/rooms" in views directory "E:\Angular\project1\views"
at Function.render (E:\Angular\project1\node_modules\express\lib\application.js:580:17)
at ServerResponse.render (E:\Angular\project1\node_modules\express\lib\response.js:1012:7)
at Query.<anonymous> (E:\Angular\project1\server.js:30:13)
at Query.<anonymous> (E:\Angular\project1\node_modules\mysql\lib\Connection.js:525:10)
at Query._callback (E:\Angular\project1\node_modules\mysql\lib\Connection.js:491:16)
at Query.Sequence.end (E:\Angular\project1\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
at Query._handleFinalResultPacket (E:\Angular\project1\node_modules\mysql\lib\protocol\sequences\Query.js:139:8)
at Query.EofPacket (E:\Angular\project1\node_modules\mysql\lib\protocol\sequences\Query.js:123:8)
at Protocol._parsePacket (E:\Angular\project1\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (E:\Angular\project1\node_modules\mysql\lib\protocol\Parser.js:433:10)
在目录中,我没有像“视图”这样的文件夹,只有src文件和其他json,node文件。如果有人知道更好的连接服务器的方法,请告诉我(任何参考)
---------------------这是用于服务器连接的代码--------------
var express = require('express');
var http = require('http');
var mysql = require('mysql');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));
app.set('view engine','html');
app.use('/js',express.static(__dirname + '/node_modules/bootstrap/dist/js'));
app.use('/js',express.static(__dirname + '/node_modules/tether/dist/js'));
app.use('/js',express.static(__dirname + '/node_modules/jquery/dist'));
app.use('/css',express.static(__dirname + '/node_modules/bootstrap/dist/css'));
app.engine('html', require('ejs').renderFile);
const con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "mydb"
});
app.get('/',function(req, res){
con.query("SELECT * FROM rooms ",function (err,result){
res.render('app/rooms',{
pageTitle: "Rooms List",
items: result
});
});
});
var server = app.listen(4200,function(){
console.log("Server started on 4200.....");
})
答案 0 :(得分:0)
从这里我可以看到,您已经在设置视图引擎以从服务器渲染视图。但是您说您正在使用Angular。因此,您不需要设置视图引擎。 这两个代码应删除。除非您正在执行服务器渲染,否则您将需要使用视图文件夹中的内容从服务器渲染页面。
app.set('view engine','html'); app.engine('html',require('ejs')。renderFile);
但是,如果您不执行服务器渲染之类的操作,则只需删除与视图有关的代码即可。