github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/docs/_functions/global/require.md (about) 1 --- 2 name: require 3 parameters: 4 - path 5 --- 6 7 `require(...)` behaves similarly to its equivalent in node.js. You can use it 8 to split your configuration across multiple files. If the path starts with a 9 `.`, it is calculated relative to the current file. For example: 10 11 {% include startExample.html %} 12 {% highlight js %} 13 14 // dnsconfig.js 15 require('kubernetes/clusters.js'); 16 17 D("mydomain.net", REG, PROVIDER, 18 IncludeKubernetes() 19 ); 20 21 {%endhighlight%} 22 23 {% highlight js %} 24 25 // kubernetes/clusters.js 26 require('./clusters/prod.js'); 27 require('./clusters/dev.js'); 28 29 function IncludeKubernetes() { 30 return [includeK8Sprod(), includeK8Sdev()]; 31 } 32 33 {%endhighlight%} 34 35 {% highlight js %} 36 37 // kubernetes/clusters/prod.js 38 function includeK8Sprod() { 39 return [ /* ... */ ]; 40 } 41 42 {%endhighlight%} 43 44 {% highlight js %} 45 46 // kubernetes/clusters/dev.js 47 function includeK8Sdev() { 48 return [ /* ... */ ]; 49 } 50 51 {%endhighlight%} 52 {% include endExample.html %} 53 54 You can also use it to require json files and initialize variables with it: 55 For Example: 56 57 {% include startExample.html %} 58 {% highlight js %} 59 60 // dnsconfig.js 61 var domains = require('./domain-ip-map.json') 62 63 for (var domain in domains) { 64 D(domain, REG, PROVIDER, 65 A("@", domains[domain]) 66 ); 67 } 68 69 {%endhighlight%} 70 71 {%highlight js %} 72 // domain-ip-map.json 73 { 74 "mydomain.net": "1.1.1.1", 75 "myotherdomain.org": "5.5.5.5" 76 } 77 {%endhighlight} 78 {% include endExample.html %}