0
我有這個簡單的NodeJS代碼的NodeJS錯誤:無法找到模塊「的翻譯:」
var express = require('express'),
app = express();
app.disable('x-powered-by');
var handleBars = require('express-handlebars').create({defaultLayout:'main'});
app.engine('handlebars',handleBars.engine);
app.set('view engine',handleBars);
app.set('port',process.env.PORT || 3000);
app.get('/',function(req,res){
res.render('home');
})
app.listen(app.get('port'),function(){
console.log('Working boy');
})
和兩個文件main.handlebars and home.handlebars
。但是當我運行這段代碼是給了我這個以下錯誤
Error: Cannot find module '[object Object]'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at new View (/Users/muradshahmammadli/Desktop/progr/NodeJS/node_modules/express/lib/view.js:79:30)
at EventEmitter.render (/Users/muradshahmammadli/Desktop/progr/NodeJS/node_modules/express/lib/application.js:570:12)
at ServerResponse.render (/Users/muradshahmammadli/Desktop/progr/NodeJS/node_modules/express/lib/response.js:971:7)
at /Users/muradshahmammadli/Desktop/progr/NodeJS/express.js:15:6
at Layer.handle [as handle_request] (/Users/muradshahmammadli/Desktop/progr/NodeJS/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/muradshahmammadli/Desktop/progr/NodeJS/node_modules/express/lib/router/route.js:137:13)
我試圖用res.send("works");
替換res.render('home');
,它工作,但我需要包括主頁,所以我能做什麼?
'app.set( '的視圖引擎', '把手');' –
@PatrickRoberts哦感謝它的工作! – user8615957