我试图将我的简单节点js Web应用程序放在AWS EB上,但似乎路径有问题。我正在计算机上运行Windows,并且可以运行,但是在EB上部署它时,出现以下错误
Error: Failed to lookup view "pages/home" in views directory "/var/app/views"
at EventEmitter.render (/var/app/current/node_modules/express/lib/application.js:579:17)
at ServerResponse.render (/var/app/current/node_modules/express/lib/response.js:961:7)
at null.<anonymous> (/var/app/current/controller/app.js:113:14)
at tryCatcher (/var/app/current/node_modules/bluebird/js/release/util.js:16:23)
at Promise.successAdapter [as _fulfillmentHandler0] (/var/app/current/node_modules/bluebird/js/release/nodeify.js:23:30)
at Promise._settlePromise (/var/app/current/node_modules/bluebird/js/release/promise.js:557:21)
at Promise._settlePromise0 (/var/app/current/node_modules/bluebird/js/release/promise.js:605:10)
at Promise._settlePromises (/var/app/current/node_modules/bluebird/js/release/promise.js:684:18)
at Async._drainQueue (/var/app/current/node_modules/bluebird/js/release/async.js:126:16)
at Async._drainQueues (/var/app/current/node_modules/bluebird/js/release/async.js:136:10)
at Immediate.Async.drainQueues [as _onImmediate] (/var/app/current/node_modules/bluebird/js/release/async.js:16:14)
at processImmediate [as _immediateCallback] (timers.js:383:17)
我的路径代码
var path = require('path');
var app = express();
app.use(express.static(path.resolve('../public')));
app.set('views',path.resolve('../views'));
app.set('view engine', 'ejs');
最佳答案
我假设您正在使用path模块来解析目录和文件名(以避免Windows和linux文件系统之间的差异问题)。
可能是文件权限或所有权问题。检查运行节点进程的用户是否对相关目录和文件具有读取权限。
这也可能是路径解析问题。看起来您的应用程序位于/ var / app / current /中,但是您试图在/ var / app / views /中查找文件。如果这是您应用的结构,则应该可以工作,但是如果您打算在/ var / app / current / views /中查找文件,那将会是有问题的。