1
我的nodejs應用程序文件夾結構如下所示。錯誤:ENOENT,沒有這樣的文件或目錄'/ var/www/html /視圖,而在ubuntu上發佈應用程序
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'\\' – baao
你真棒@baao請寫下我接受的答案 –