错误:在Ubuntu上发布应用程序时,ENOENT,没有这样的文件或目录'/ var / www / html / views

我的nodejs应用程序文件夹结构如下所示。

Index.html文件位于views文件夹中,公用文件夹包含partials页面。

下面是index.html中的一小段代码,当节点在本地机器上运行时,它工作正常。

<section id="sidebar" ng-controller="menuController" ng-init="init()"> <% include ..\public\partials\_menubar.html %> </section> 

在这里输入图像说明

但是,当我在服务器上运行的代码,它给了我错误。

 Error: ENOENT, no such file or directory '/var/www/html/views/..\public\partials\_menubar.html' at Object.fs.openSync (fs.js:432:18) at Object.fs.readFileSync (fs.js:286:15) at includeSource (/var/www/html/node_modules/ejs/lib/ejs.js:194:17) at /var/www/html/node_modules/ejs/lib/ejs.js:528:26 at Array.forEach (native) at Object.Template.generateSource (/var/www/html/node_modules/ejs/lib/ejs.js:505:15) at Object.Template.compile (/var/www/html/node_modules/ejs/lib/ejs.js:427:12) at Object.compile (/var/www/html/node_modules/ejs/lib/ejs.js:288:16) at handleCache (/var/www/html/node_modules/ejs/lib/ejs.js:147:16) at View.exports.renderFile [as engine] (/var/www/html/node_modules/ejs/lib/ejs.js:350:14) 

我曾尝试使用下面的代码,但没有成功。

 app.use(express.static(path.join(__dirname, 'public'))); 

Linux使用/作为目录分隔符,因此在使用windows' \ separator'时找不到文件。

还要注意,除了windows以外,linux是区分大小写的,所以你需要确保在你的文件/目录名中有正确的大小写。