title: Why does importing a router for express in TypeScript not work
body: <p>I am trying to set up a simple Hello World REST service using NodeJS and typescript. I want to separate the routers into different files, but somehow it doesn't work out. </p>
  
  <p>Simply put, for a GET call to <code>http://localhost:3000/welcome/hi</code> , why does <strong>Project 1</strong> work, but <strong>Project 2</strong> not? I've tried to look for tutorials but the code doesn't seem to work the way I want them to.</p>
  
  <p><strong>Project 1</strong></p>
  
  <pre><code>import express from "express";
  import { Router, Request, Response } from "express";
  
  const app: express.Application = express();
  const port: any = process.env.PORT || 3000;
  
  const router: Router = Router();
  const welcomeRouter: Router = Router();
  
  welcomeRouter.get("/", (req: Request, res: Response) =&gt; {
      res.send({"message": "Welcome!"});
  });
  
  welcomeRouter.get("/:name", (req: Request, res: Response) =&gt; {
      let { name } = req.params;
  
      res.send(`Hello, ${name}!`);
  });
  
  router.get("/", (req: Request, res: Response) =&gt; {
      res.send({"message":"Hello, World!"});
  });
  
  app.use("/", router);
  app.use("/welcome", welcomeRouter);
  
  
  app.listen(port, () =&gt; {
      console.log(`Listening at http://localhost:${port}/`);
  });
  </code></pre>
  
  <p><strong>Project 2</strong></p>
  
  <p><strong>./app.ts</strong></p>
  
  <pre><code>import { Router, Request, Response } from "express";
  
  const router: Router = Router();
  
  router.get("/", (req: Request, res: Response) =&gt; {
      res.send({"message": "Welcome!"});
  });
  
  router.get("/:name", (req: Request, res: Response) =&gt; {
      let { name } = req.params;
  
      res.send(`Hello, ${name}!`);
  });
  
  export default router;
  </code></pre>
  
  <p><strong>./server.ts</strong></p>
  
  <pre><code>import express from "express";
  import { Router, Request, Response } from "express";
  
  import welcomeRouter from "./app";
  
  const app: express.Application = express();
  const port: any = process.env.PORT || 3000;
  
  const router: Router = Router();
  
  app.use("/welcome", welcomeRouter);
  
  router.get("/", (req: Request, res: Response) =&gt; {
      res.send({"message":"Hello, World!"});
  });
  
  app.use("/", router);
  app.use("/welcome", welcomeRouter);
  
  app.listen(port, () =&gt; {
      console.log(`Listening at http://localhost:${port}/`);
  });
  </code></pre>