#Can I specify inside import relative path to all files instead of one specifically?

14 messages · Page 1 of 1 (latest)

steady ermine
#

I'm trying to find the way how to specify relative path to the todo folder:
https://github.com/invzbl3/project/tree/main/src/todo

to use it then inside imports of the Module:

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TodosController } from 'src/todo/todo.controller';
import { TodosModule } from 'src/todo/todo.module';
import { TodosService } from 'src/todo/todo.service';

@Module({
  imports: [TodosController, TodosModule, TodosService],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}```

https://github.com/invzbl3/project/blob/main/src/app.module.ts#L9

Can someone tell me, please, how can I specify relative path to the folder to use it in `imports` instead of using import for each file separately.
GitHub

Nest.js application and its CRUD operations. Contribute to invzbl3/project development by creating an account on GitHub.

GitHub

Nest.js application and its CRUD operations. Contribute to invzbl3/project development by creating an account on GitHub.

#

I've already tried to specify in the following way as:

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Todos } from './todo/todo';

@Module({
  imports: [Todos],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

but it doesn't look as correct way

tribal yew
#
  1. take the controller and service out of the imports array, they don't belong there
steady ermine
tribal yew
#

Are you talking about using a barrel file so you can do somethin like import { TodoModule, TodoController, TodoService } from './todo?

steady ermine
steady ermine
tribal yew
#

You need to make an index.ts file at the route where you want the barrel to be, then you use export * from './path/to/file/to/export/from as many times as necessary to export all of the things you want to export

#

Very commonly used in npm packages. Take a look at this one for example: https://github.com/jmcdo29/ogma/blob/main/packages/nestjs-module/src/index.ts

export * from './decorators';
export * from './interceptor/ogma.interceptor';
export * from './interceptor/providers';
export * from './interfaces/ogma-options.interface';
export * from './ogma.module';
export { createProviderToken } from './ogma.provider';
export * from './ogma.service';
steady ermine
#

thank you for your example! I appreciate it.

steady ermine
#

I think I'll remove this question a bit later.

tribal yew
steady ermine
#

Okay, I got your point here👍