我知道如何在命令行中运行脚本,使用
我的问题与此不同,现在我可以运行脚本,那么我可以在项目中使用模块内部的服务吗?假设我有这个结构,通常由其他模块在项目中调用:
npm
或npx ts-node [script.ts]
,就像这里所述一样。我的问题与此不同,现在我可以运行脚本,那么我可以在项目中使用模块内部的服务吗?假设我有这个结构,通常由其他模块在项目中调用:
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');
}
}
我怎样才能在文件 /src/script.ts
中调用 bar()
,并且在保留所有导入的情况下运行 npx ts-node script.ts
?谢谢。