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

299
Vistas
TypeError: Cannot read properties of undefined (reading 'use')

I am getting an error (TypeError: Cannot read properties of undefined (reading 'use')) when I try to run the 'node server.js' cmd from the Terminal. It shows an error in my auth.routes.js file.

TypeError: Cannot read properties of undefined (reading 'use')

Here is the content of my 'auth.routes.js' file:

import verifySignUp from "../middleware/index.js";
import controller from "../controllers/auth.controller.js";

export default function(app) {
  app.use(function(req, res, next) {
    res.header(
      "Access-Control-Allow-Headers",
      "x-access-token, Origin, Content-Type, Accept"
    );
    next();
  });

  app.post(
    "/api/auth/signup",
    [
      verifySignUp.checkDuplicateUsernameOrEmail,
      verifySignUp.checkRolesExisted
    ],
    controller.signup
  );

  app.post("/api/auth/signin", controller.signin);
};

I refer to it in the 'server.js' file. See below:

// routes
import authRoute from './app/routes/auth.routes.js';
import userRoute from './app/routes/user.routes.js';
app.route = authRoute();
app.route = userRoute();

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

0

Why are you creating "route" property on "app" object? You don't have to set properties to express's "app" object. What treats to your error - you need to organize your code in this way:

// auth.routes.js

import verifySignUp from "../middleware/index.js";
import controller from "../controllers/auth.controller.js";

export default function(app) {
  app.use(function(req, res, next) {
    res.header(
      "Access-Control-Allow-Headers",
      "x-access-token, Origin, Content-Type, Accept"
    );
    next();
  });

  app.post(
    "/api/auth/signup",
    [
      verifySignUp.checkDuplicateUsernameOrEmail,
      verifySignUp.checkRolesExisted
    ],
    controller.signup
  );

  app.post("/api/auth/signin", controller.signin);
};

// server.js

import initializeAuthRoute from './app/routes/auth.routes.js';
import initializeUserRoute from './app/routes/user.routes.js';
initializeAuthRoute(app);
initializeUserRoute(app);
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