Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

javascript - HBS没有在node.js中定义?(hbs is not define in node.js?)

I have install handlebars for template handling in node.js app and set the engine to hbs but during runtime it says that ReferenceError: hbs is not defined .(我在node.js应用程序中安装了用于模板处理的车把并将引擎设置为hbs,但是在运行时它说ReferenceError:hbs未定义 。)

const express = require('express'); const app = express(); const PORT = 8080; const HOST = '0.0.0.0'; app.engine('handlebars', hbs.engine); app.set('view engine', 'handlebars'); app.get('/home',(req,res)=>{ res.render('home'); }); app.listen(PORT, HOST); console.log(`Running on http://${HOST}:${PORT}`); How to resolve this problem ?(如何解决这个问题?)   ask by Tabish translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you need to install hbs first(您需要先安装HBS)

npm install express-handlebars const expressHbs = require('express-handlebars'); then set engine(然后设置引擎) app.engine('.hbs', expressHbs({defaultLayout: 'layout', extname: '.hbs'})); app.set('view engine', '.hbs');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...