Created
November 6, 2020 13:27
-
-
Save akwodkiewicz/a18a7de37bf3dce331825a1311054232 to your computer and use it in GitHub Desktop.
NestJs in node REPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For this trick you'll need: | |
// | |
// $ node --experimental-repl-await | |
// | |
// If you happen to use Typescript alias paths, you'll also want to install `tsconfig-paths` | |
// and actually run the node REPL with: | |
// | |
// $ TS_NODE_PROJECT=path/to/tsconfig.json node -r tsconfig-paths/register --experimental-repl-await | |
// | |
// All the statements need to be input inside REPL. | |
let { NestFactory } = require('@nestjs/core') | |
// importing whole app module | |
let { AppModule } = require('./dist/src/app.module') | |
// instantiating whole app (module) | |
appModule = await NestFactory.create(AppModule); | |
// extracting particular services | |
someService = appModule.get('SomeService'); | |
// If you want to use single services which have other dependencies, you will need | |
// to import a *service* (not a module) and inject the dependencies yourself. | |
let { MyServiceWhichNeedsHttpService } = require('./dist/src/something') | |
let { HttpModule } = require('@nestjs/common') | |
httpModule = await NestFactory.create(HttpModule); | |
httpService = httpModule.get('HttpService'); | |
myService = new MyServiceWhichNeedsHttpService(httpService); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment