Cannot read property 'render' of undefined

304
August 15, 2017, at 8:24 PM

i am making a simple program in koa.js in which i am trying to rendering the information to the html page i.e index.html and whenever i trying to run the code it gives the error.. i am tired of this thing, still can't find a better solution..

TypeError: Cannot read property 'render' of undefined at Object.render (C:\Users\hamza\Desktop\TheFirstKoaApp\Task3\app.js:27:8) at next (native) at Object.dispatch (C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules \koa-router\lib\router.js:331:14) at next (native) at onFulfilled (C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules\co\index.js:65:19) at C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules\co\index.js:54:5 at Object.co (C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules\co\index.js:50:10) at Object.toPromise (C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules\co\index.js:119:63) at next (C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules\co\index.js:100:29) at onFulfilled (C:\Users\hamza\Desktop\TheFirstKoaApp\node_modules\co\index.js:70:7) at process._tickCallback (node.js:368:9)

here is my 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>
Rent Charter Buses Company
READ ALSO
Compiling native node addon with c++ 17 inside fails during npm install on ubuntu

Compiling native node addon with c++ 17 inside fails during npm install on ubuntu

I have native add-on for nodejs that uses c++17 features, specifically "shared_mutex"When I call npm install which downloads and compiles the add-on i get an error:

437
Node js request module get different type (format) of return value from server?

Node js request module get different type (format) of return value from server?

I use request library to access web service, but I found that the return value can be different

275
How do I re-arrange how my loop works?

How do I re-arrange how my loop works?

I am working on a message board and i want the new topics to be the first in lineI am using a forEach loop to print out all the Topics but the new ones are going under the old ones

286
npm install with 2 projects in one docker image

npm install with 2 projects in one docker image

I have a docker container that combines 2 node projects into oneProject A is the statsd project and project B is a postgres backend project that writes to a postgres database using the npm package pg

234