> For the complete documentation index, see [llms.txt](https://commandbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://commandbox.ortusbooks.com/task-runners/loading-ad-hoc-modules.md).

# Loading Ad-hoc Modules

If you have a module installed to a folder that you wish to load into the CLI and use on-the-fly during a task runner, you can do so like this:

```
loadModule( 'build/modules/myUtils' );
```

That code will load the `myUtils` module right there into the core CLI. Note, the module needs to be compatible with CommandBox. All models, interceptors, or commands inside the module will instantly be available in the CLI.

This means your task runners can rely on other functionality in the form of modules which are easily distributed and shared. While you could manually install the module globally into the CLI, this method is more flexible and ad-hoc as the module is just temporarily loaded.

### Considerations

* Modules aren't unloaded for you. You can do so via `ModuleService.unload( 'myUtils' )` if you like.
* If a module of that name is already loaded, nothing happens. That means if you modify the module, you'll need to `reload` the shell to pick up those changes.
* The path to the module can be absolute, but if relative, it will be resolved relative to the task runner CFC, not the current working directory of the shell.

### Loading Multiple Modules

A task runner with an entire folder of modules to load may run into timing issues where one module requires another to be loaded before it can load. To handle this, instead of loading each module one at a time with `loadModule()` you can load an entire array of modules at ones with `loadModules()`.

1. First all modules in the array are registered with the `ModuleService`.
2. Then each module is activated

This function takes an array of absolute module paths to load.

```javascript
loadModules( [
  "C:/path/to/module1",
  "C:/path/to/module2",
  "C:/path/to/module3"
] );
```

You can easily drive this function with `directoryList()` like so:

```javascript
loadModules(
    directoryList( path=resolvePath( 'modules/' ), type='dir' )
);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://commandbox.ortusbooks.com/task-runners/loading-ad-hoc-modules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
