I know how to run a script from command line, using npm
or npx ts-node [script.ts]
just as stated here.
My question is different, now that I can run scripts, can I use services that are inside modules in my project? Let's say that I have this structure that it is normally called inside the project by other modules:
foo/foo.module.ts
import { HttpModule, Module } from '@nestjs/common';
@Module({
providers: [FooService],
imports: [HttpModule],
exports: [FooService]
})
export class FooModule { }
foo/foo.service.ts
import { HttpService, Injectable } from '@nestjs/common';
@Injectable()
export class FooService {
constructor(
private readonly httpService: HttpService,
) {}
bar() {
console.log('do stuff');
}
}
how can I call bar()
inside the file /src/script.ts
and then call npx ts-node script.ts
keeping all the imports? Thank you.