1

I'm creating a new project with node.js, express.js and typescript.

I decided to use absolute paths, but I'm not very satisfied, because when I import files, it doesn't recognize automatically index.ts files.

My folder structure:

|--routes
|  |--index.ts
|  |--user.routes.ts
|--models
|  |--index.ts
|  |--user.ts
|--controllers
|  |--index.ts
|  |--user.controller.ts
|--services
|  |--index.ts
|  |--user.services.ts
|--index.ts

And my imports are like:

import { mainRouter } from '@routes/index';

I wanted it like:

import { mainRouter } from '@routes';

I read something about it, and said that absolute paths treats every file as a folder, that's why it happens.

Is there a way to solve this?

jabaa
  • 5,844
  • 3
  • 9
  • 30
Henrique
  • 123
  • 1
  • 9
  • 3
    _"absolute paths treats every file as a folder"_ That's wrong. `@routes` isn't a path. You have an alias for it in your configuration. You can add the `index.ts` file to this configuration. – jabaa May 10 '22 at 21:06

0 Answers0