Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

619
Vistas
Error: Route.get() requires a callback function but got a [object Undefined] while using imported function

I am checking if a user is logged in a route called forum. I am importing it like this. The file is routes/forum.js

const isloggedinimport = require('../index')

I have the function on index.js

const isloggedin = (req,res,next) => {
  if(req.user) {
    next()
  }
  else {
    res.render('loginerror',)
  }
}

I am exporting with

module.exports = isloggedin 

When I try to run this


router.get('/', isloggedinimport.isloggedin, (req, res) => { 
    res.render('monitors/monitorhome')
});


module.exports = router

I get the error that Route.get() requires a callback function but got a [object Undefined]

The error is on this line

router.get('/', isloggedinimport.isloggedin, (req, res) => { 

How do I fix this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When exporting the function, try using the following code:

module.exports.isloggedin = isloggedin

This will set the property isloggedin to the function so that when you call isloggedinimport.isloggedin, it will access the function properly. Alternatively, you could use the following code to export your function:

module.exports = isloggedin

and then use this code to import the function:

const isloggedin = require('../index')

...

router.get('/', isloggedin, (req, res) => { 
    res.render('monitors/monitorhome')
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda