title: How to app use all routes from different file
body: <p>I'm trying to separate my routes, previously i'm including them to my app.js</p>
  
  <p>/backend/app.js</p>
  
  <pre><code>const express = require("express");
  const router = require("./routes");
  const status = require("./routes/status");
  const register = require("./routes/register");
  const login = require("./routes/login");
  
  
  app.use('/', router);
  app.use('/status', status);
  app.use('/login', login);
  app.use('/register', register);
  </code></pre>
  
  <p>I realized its not ideal since i am adding more and more routes later on and the app.js will be polluted with them</p>
  
  <p>What i want to do now is just to import an index.js to app.js and basically this index have all the routes needed</p>
  
  <p>/backend/routes/index</p>
  
  <pre><code>const routes = require("express").Router();
  const root = require("./root");
  const status = require("./status");
  const register = require("./account/register");
  const login = require("./account/login");
  
  
  routes.use("/",  root);
  routes.use("/login", login);
  routes.use("/register", register);
  routes.use("/status", status);
  and now in the app.js i can just include the index
  
  const routes = require("./routes");
  app.use('/', routes);
  </code></pre>
  
  <p>but its not working im getting 404 error when trying to request to login route</p>
  
  <p>im exporting them like this</p>
  
  <p><code>module.exports = routes;</code></p>