Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!