Skip to content

Commit daf4269

Browse files
Merge pull request #2600 from strapi/cms/fix-problem-expand-strapi-console-docs
Extend strapi.console documentation
2 parents f26287d + fbcd70e commit daf4269

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

docusaurus/docs/cms/cli.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,37 @@ strapi telemetry:enable
564564

565565
## strapi console
566566

567-
Start the server and eval commands in your application in real time.
567+
Start the server and evaluate commands in your application in real time.
568568

569569
```bash
570570
strapi console
571571
```
572572

573+
The `console` command compiles and loads your application, starts the server in the background, then opens a Node.js <ExternalLink to="https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop" text="REPL"/>. The REPL provides a prompt based on your application's name and gives access to all Strapi APIs through the global `strapi` object. Closing the REPL by pressing `Ctrl-C` twice gracefully stops the server.
574+
575+
### Available helpers
576+
577+
The `strapi` object exposes the following getters and methods to interact with your application:
578+
579+
- `strapi.services` and `strapi.service(uid)` to use [services](/cms/backend-customization/services)
580+
- `strapi.controllers` and `strapi.controller(uid)` to call [controllers](/cms/backend-customization/controllers)
581+
- `strapi.contentTypes` and `strapi.contentType(uid)` to inspect [content-types](/cms/backend-customization/models)
582+
- `strapi.components` to list components
583+
- `strapi.policies` and `strapi.policy(name)` for [policies](/cms/backend-customization/policies)
584+
- `strapi.middlewares` and `strapi.middleware(name)` for [middlewares](/cms/backend-customization/middlewares)
585+
- `strapi.plugins` and `strapi.plugin(name)` for plugins
586+
- `strapi.hooks` and `strapi.hook(name)` for hooks
587+
- `strapi.apis` and `strapi.api(name)` for APIs
588+
- `strapi.db` to directly query the database through the [Query Engine API](/cms/api/query-engine), for example as follows:<br/><br/>
589+
```js
590+
await strapi.db.query('api::article.article').findMany();
591+
```
592+
593+
Use this environment to test code and inspect your project with direct access to all Strapi APIs.
594+
595+
:::note
596+
Strapi uses a Node.js feature called <ExternalLink to="https://nodejs.org/api/async_context.html" text="AsyncLocalStorage"/> to make the context available anywhere.
597+
:::
573598
## strapi version
574599

575600
Print the currently installed Strapi version.

0 commit comments

Comments
 (0)