Skip to content

Commit 6c6e834

Browse files
docs: update devtools docs
1 parent 02f47d6 commit 6c6e834

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

content/devtools/ci-cd.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ To see reports, navigate to the project's corresponding page (see organizations)
5151

5252
<figure><img src="/assets/devtools/report.png" /></figure>
5353

54+
This is particularly helpful in identifying changes that may have gone unnoticed during code reviews. For instance, let's say someone has changed the scope of a **deeply nested provider**. This change might not be immediately obvious to the reviewer, but with Devtools, we can easily spot such changes and make sure that they're intentional. Or if we remove a guard from a specific endpoint, it will show up as affected in the report. Now if we didn't have integration or e2e tests for that route, we might not notice that it's no longer protected, and by the time we do, it could be too late.
55+
56+
Similarly, if we're working on a **large codebase** and we modify a module to be global, we'll see how many edges were added to the graph, and this - in most cases - is a sign that we're doing something wrong.
57+
5458
#### Build preview
5559

5660
For every published graph we can go back in time and preview how it looked before by clicking at the **Preview** button. Furthermore, if the report was generated, we should see the differences higlighted on our graph:
@@ -63,6 +67,8 @@ See screenshot below:
6367

6468
<figure><img src="/assets/devtools/nodes-selection.png" /></figure>
6569

70+
The ability to go back in time lets you investigate and troubleshoot the issue by comparing the current graph with the previous one. Depending on how you set things up, every pull request (or even every commit) will have a corresponding snapshot in the registry, so you can easily go back in time and see what changed. Think of Devtools as a Git but with an understanding of how Nest constructs your application graph, and with the ability to **visualize** it.
71+
6672
#### Integrations: Github Actions
6773

6874
First let's start from creating a new Github workflow in the `.github/workflows` directory in our project and call it, for example, `publish-graph.yml`. Inside this file, let's use the following definition:

content/devtools/overview.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Once the `DevtoolsModule` is imported and your application is up and running (`n
4444

4545
<figure><img src="/assets/devtools/modules-graph.png" /></figure>
4646

47+
> info **Hint** As you can see on the screenshot above, every module connect to the `InternalCoreModule`. `InternalCoreModule` is a global module that is always imported into the root module. Since it's registered as a global node, Nest automatically creates edges between all of the modules and the `InternalCoreModule` node. Now, if you want to hide global modules from the graph, you can use the "Hide global modules" checkbox (in the sidebar).
48+
4749
So as we can see, `DevtoolsModule` makes your application expose an additional HTTP server (on port 8000) that the Devtools application will use to introspect your app.
4850

4951
Just to double-check that everything works as expected, change the graph view to "Classes". You should see the following screen:
@@ -56,10 +58,14 @@ To focus on a specific node, click on the rectangle and the graph will show a po
5658
5759
<figure><img src="/assets/devtools/node-popup.png" /></figure>
5860

61+
> info **Hint** To export a graph as an image, click on the **Export as PNG** button in the right corner of the graph.
62+
5963
Using the form controls located in the sidebar (on the left), you can control edges proximity to, for example, visualize a specific application sub-tree:
6064

6165
<figure><img src="/assets/devtools/subtree-view.png" /></figure>
6266

67+
This can be particularly useful when you have **new developers** on your team and you want to show them how your application is structured. You can also use this feature to visualize a specific module (e.g. `TasksModule`) and all of its dependencies, which can come in handy when you're breaking down a large application into smaller modules (for example, individual micro-services).
68+
6369
#### Investigating the "Cannot resolve dependency" error
6470

6571
> info **Note** This feature is supported for `@nestjs/core` >= `v9.3.10`.
@@ -106,24 +112,46 @@ When you navigate to the **Routes explorer** page, you should see all of the reg
106112

107113
<figure><img src="/assets/devtools/routes.png" /></figure>
108114

115+
> info **Hint** This page shows not only HTTP routes, but also all of the other entrypoints (e.g. WebSockets, gRPC, GraphQL resolvers etc.).
116+
117+
Entrypoints are grouped by their host controllers. You can also use the search bar to find a specific entrypoint.
118+
119+
If you click on a specific entrypoint, **a flow graph** will be displayed. This graph shows the execution flow of the entrypoint (e.g. guards, interceptors, pipes, etc. bound to this route). This is particularly useful when you want to understand how the request/response cycle looks for a specific route, or when troubleshooting why a specific guard/interceptor/pipe is not being executed.
120+
109121
#### Sandbox
110122

111123
To execute JavaScript code on the fly & interact with your application in real-time, navigate to the **Sandbox** page:
112124

113125
<figure><img src="/assets/devtools/sandbox.png" /></figure>
114126

127+
The playground can be used to test and debug API endpoints in **real-time**, allowing developers to quickly identify and fix issues without using, for example, an HTTP client. We can also bypass the authentication layer, and so we no longer need that extra step of logging in, or even a special user account for testing purposes. For event-driven applications, we can also trigger events directly from the playground, and see how the application reacts to them.
128+
129+
Anything that gets logged down is streamlined to the playground's console, so we can easily see what's going on.
130+
131+
Just execute the code **on the fly** and see the results instantly, without having to rebuild the application and restart the server.
132+
133+
<figure><img src="/assets/devtools/sandbox-table.png" /></figure>
134+
135+
> info **Hint** To pretty display an array of objects, use the `console.table()` (or just `table()`) function.
136+
115137
#### Bootstrap performance analyzer
116138

117139
To see a list of all class nodes (controllers, providers, enhancers, etc.) and their corresponding instantiation times, navigate to the **Bootstrap performance** page:
118140

119141
<figure><img src="/assets/devtools/bootstrap-performance.png" /></figure>
120142

143+
This page is particularly useful when you want to identify the slowest parts of your application's bootstrap process (e.g. when you want to optimize the application's startup time which is crucial for, for example, serverless environments).
144+
121145
#### Audit
122146

123147
To see the auto-generated audit - errors/warnings/hints that the application came up with while analyzing your serialized graph, navigate to the **Audit** page:
124148

125149
<figure><img src="/assets/devtools/audit.png" /></figure>
126150

151+
> info **Hint** The screenshot above doesn't show all of the available audit rules.
152+
153+
This page comes in handy when you want to identify potential issues in your application.
154+
127155
#### Preview static files
128156

129157
To save a serialized graph to a file, use the following code:
@@ -138,3 +166,5 @@ fs.writeFileSync('./graph.json', app.get(SerializedGraph).toString());
138166
Then you can drag and drop this/upload this file:
139167

140168
<figure><img src="/assets/devtools/drag-and-drop.png" /></figure>
169+
170+
This is helpful when you want to share your graph with someone else (e.g., co-worker), or when you want to analyze it offline.

src/assets/devtools/sandbox-table.png

327 KB
Loading

0 commit comments

Comments
 (0)