### Standalone applications There are several ways of mounting a Nest application. You can create a web app, a microservice or just a bare Nest **standalone application** (without any network listeners). The Nest standalone application is a wrapper around the Nest **IoC container**, which holds all instantiated classes. We can obtain a reference to any existing instance from within any imported module directly using the standalone application object. Thus, you can take advantage of the Nest framework anywhere, including, for example, scripted **CRON** jobs. You can even build a **CLI** on top of it. #### Getting started To create a Nest standalone application, use the following construction: ```typescript @@filename() async function bootstrap() { const app = await NestFactory.createApplicationContext(AppModule); // your application logic here ... } await bootstrap(); ``` #### Retrieving providers from static modules The standalone application object allows you to obtain a reference to any instance registered within the Nest application. Let's imagine that we have a `TasksService` provider in the `TasksModule` module that was imported by our `AppModule` module. This class provides a set of methods that we want to call from within a CRON job. ```typescript @@filename() const tasksService = app.get(TasksService); ``` To access the `TasksService` instance we use the `get()` method. The `get()` method acts like a **query** that searches for an instance in each registered module. You can pass any provider's token to it. Alternatively, for strict context checking, pass an options object with the `strict: true` property. With this option in effect, you have to navigate through specific modules to obtain a particular instance from the selected context. ```typescript @@filename() const tasksService = app.select(TasksModule).get(TasksService, { strict: true }); ``` Following is a summary of the methods available for retrieving instance references from the standalone application object.
get()
|
Retrieves an instance of a controller or provider (including guards, filters, and so on) available in the application context. |
select()
|
Navigates through the module's graph to pull out a specific instance of the selected module (used together with strict mode as described above). |