2020-08-20 02:00:40 +08:00
---
name: require_glob
parameters:
- path
- recursive
2023-01-13 05:59:42 +08:00
parameter_types:
path: string
recursive: boolean
2020-08-20 02:00:40 +08:00
---
2023-09-14 22:25:45 +08:00
`require_glob()` recursively loads `.js` files that match a glob (wildcard). The recursion can be disabled.
2020-08-20 02:00:40 +08:00
Possible parameters are:
- Path as string, where you would like to start including files. Mandatory. Pattern matching possible, see [GoLand path/filepath/#Match docs ](https://golang.org/pkg/path/filepath/#Match ).
- If being recursive. This is a boolean if the search should be recursive or not. Define either `true` or `false` . Default is `true` .
Example to load `.js` files recursively:
2022-02-18 01:22:31 +08:00
2023-03-14 04:30:21 +08:00
{% code title="dnsconfig.js" %}
2023-01-20 20:56:20 +08:00
```javascript
2020-08-20 02:00:40 +08:00
require_glob("./domains/");
```
2023-03-14 04:30:21 +08:00
{% endcode %}
2020-08-20 02:00:40 +08:00
Example to load `.js` files only in `domains/` :
2022-02-18 01:22:31 +08:00
2023-03-14 04:30:21 +08:00
{% code title="dnsconfig.js" %}
2023-01-20 20:56:20 +08:00
```javascript
2020-08-20 02:00:40 +08:00
require_glob("./domains/", false);
```
2023-03-14 04:30:21 +08:00
{% endcode %}
2020-08-20 02:00:40 +08:00
2023-09-14 22:25:45 +08:00
# Comparison to require()
`require_glob()` and `require()` both use the same rules for determining which directory path is
relative to.
This will load files being present underneath `./domains/user1/` and **NOT** at below `./domains/` , as `require_glob()`
is called in the subfolder `domains/` .
2020-08-20 02:00:40 +08:00
2023-01-30 02:02:56 +08:00
{% code title="dnsconfig.js" %}
2023-01-20 20:56:20 +08:00
```javascript
2020-08-20 02:00:40 +08:00
require("domains/index.js");
```
2023-01-30 02:02:56 +08:00
{% endcode %}
2020-08-20 02:00:40 +08:00
2023-01-30 02:02:56 +08:00
{% code title="domains/index.js" %}
2023-01-20 20:56:20 +08:00
```javascript
2020-08-20 02:00:40 +08:00
require_glob("./user1/");
```
2023-01-30 02:02:56 +08:00
{% endcode %}