Skip to content

Commit 4b4814f

Browse files
committed
docs(repl): Watch mode
1 parent 05d6294 commit 4b4814f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

content/recipes/repl.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,27 @@ Interface: $(token: InjectionToken) => any
107107
| `methods` | Display all public methods available on a given provider or controller. | `methods(token: ClassRef \| string) => void` |
108108
| `resolve` | Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception. | `resolve(token: InjectionToken, contextId: any) => Promise<any>` |
109109
| `select` | Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module. | `select(token: DynamicModule \| ClassRef) => INestApplicationContext` |
110+
111+
#### Watch mode
112+
113+
During development it is useful to run REPL in a watch mode to reflect all the code changes automatically:
114+
115+
```bash
116+
$ npm run start -- --watch --entryFile repl
117+
```
118+
119+
This has one flaw, the REPL's command history is discarded after each reload which might be cumbersome.
120+
Fortunately, there is a very simple solution. Modify your `bootstrap` function like this:
121+
122+
```typescript
123+
async function bootstrap() {
124+
const replServer = await repl(AppModule);
125+
replServer.setupHistory(".nestjs_repl_history", (err) => {
126+
if (err) {
127+
console.error(err);
128+
}
129+
});
130+
}
131+
```
132+
133+
Now the history is preserved between the runs/reloads.

0 commit comments

Comments
 (0)