I have a route that gets all of the clients in mongodb and returns them. When I try to use res.render() from with the mongoose find() callback, I get an error saying that ReferenceError: res is not defined
Here's the code that works and that I've confirmed is returning the clients:
app.get( '/clients', function( request, response ) {
return ClientModel.find( function( err, clients ) {
if( !err ) {
return response.send( clients );
} else {
return console.log( err );
}
});
});
Here's the code that I'm trying to use to render the ejs view, while passing it a list of clients:
app.get( '/clients', function( request, response ) {
return ClientModel.find( function( err, clients ) {
if( !err ) {
res.render('clients/clients.ejs', {
clients: clients
});
} else {
return console.log( err );
}
});
});
How can I get this to work?
Use response.render instead of res.render.