node.js - Cannot read property 'render' of undefined -
i making simple program in koa.js in trying rendering information html page i.e index.html , whenever trying run code gives error.. tired of thing, still can't find better solution..
typeerror: cannot read property 'render' of undefined @ object.render (c:\users\hamza\desktop\thefirstkoaapp\task3\app.js:27:8) @ next (native) @ object.dispatch (c:\users\hamza\desktop\thefirstkoaapp\node_modules \koa-router\lib\router.js:331:14) @ next (native) @ onfulfilled (c:\users\hamza\desktop\thefirstkoaapp\node_modules\co\index.js:65:19) @ c:\users\hamza\desktop\thefirstkoaapp\node_modules\co\index.js:54:5 @ object.co (c:\users\hamza\desktop\thefirstkoaapp\node_modules\co\index.js:50:10) @ object.topromise (c:\users\hamza\desktop\thefirstkoaapp\node_modules\co\index.js:119:63) @ next (c:\users\hamza\desktop\thefirstkoaapp\node_modules\co\index.js:100:29) @ onfulfilled (c:\users\hamza\desktop\thefirstkoaapp\node_modules\co\index.js:70:7) @ process._tickcallback (node.js:368:9)
here code..
app.js:
const koa = require('koa'); const router = require('koa-router'); const config = require(__dirname+"/config.js"); const app = new koa(); var route = router(); app.use(route.routes()); var views = require("co-views"); var render = views("views", { map: { html: 'swig' }}); route.all("/hi", function *(req,res){ var myuser = {name:"john"}; res.render ("index",{user:myuser}); //this.body = yield render("index"); }); startkoa(); function startkoa() { app.listen(config.koa.port); console.log('listening on port '+config.koa.port); }
index.html:
<html> <body> <script> var username = "{{user.name}}"; </script> <script src="app.js"></script> </body> </html>
Comments
Post a Comment