Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I getting this 'res.render() is not a function'

I am trying create a route, but I getting this error.

res.send is not a function

And my code in the index.js file it is this way

var express = require('express');
var router = express.Router();

router.get('/', function(res, req, next){
 res.render('index');
});

module.exports = router;

And in the app.js file is that way

var index = require('./routes/index.js');
...
...
...
app.get('/', index);

Thank you, since already.

like image 924
Matheus Fachini Avatar asked Nov 30 '22 09:11

Matheus Fachini


1 Answers

It looks like you've swapped req and res in your router.get callback. Thus, what you've named req is actually res, and vice versa, and req.render does not exist.

Try changing:

router.get('/', function(res, req, next){

to:

router.get('/', function(req, res, next){


To avoid mixing these up in the future, try to remember that requests come before responses, in both HTTP and the alphabet.

like image 63
Aaron Avatar answered Dec 05 '22 12:12

Aaron