mirror of https://gitee.com/bigwinds/arangodb
39 lines
3.1 KiB
HTML
39 lines
3.1 KiB
HTML
<html><head><title>ArangoDB Manual</title> <style media="screen" type="text/css" style="display:none">body{background-color:white;font:13px Helvetica,arial,freesans,clean,sans-serif;line-height:1.4;color:#333;}#access{font-size:16px;margin-left:12px;display:block;margin-left:10px;margin-right:10px;background-color:#F3F1EE!important;}#access a{border-right:1px solid #DBDEDF;color:#A49F96;display:block;line-height:38px;padding:0 10px;text-decoration:none;}#navigation ul{text-transform:uppercase;list-style:none;margin:0;}#navigation li{float:left;position:relative;}#container{width:920px;margin:0 auto;}a{color:#4183C4;text-decoration:none;}.contents h2{font-size:24px;border-bottom:1px solid #CCC;color:black;}.contents h1{font-size:33px;border-bottom:1px solid #CCC;color:black;}.clearfix:after{content:".";display:block;clear:both;font-size:0;height:0;visibility:hidden;}/**/ *:first-child+html .clearfix{min-height:0;}/**/ * html .clearfix{height:1%;}</style></head><body><div id="container"><img src="images/logo_arangodb.png" width="397" height="67" alt="ArangoDB"><div id="access" role="navigation"><div id="navigation"><ul id="menu-ahome" class="menu"><li><a href="Home.html">Table of contents</a></li> <li><a href="http://www.arangodb.org">ArangoDB homepage</a></li></ul></div><div class="clearfix"></div></div><div>
|
|
<!-- Generated by Doxygen 1.7.5.1 -->
|
|
</div>
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<h1>JavaScript Modules </h1> </div>
|
|
</div>
|
|
<div class="contents">
|
|
<div class="textblock"><p>The ArangoDB uses a <a href="http://wiki.commonjs.org/wiki/Modules">CommonJS</a> compatible module concept. You can use the function <code>require</code> in order to load a module. <code>require</code> returns the exported variables and functions of the module. You can use the option <code>startup.modules-path</code> to specify the location of the JavaScript files.</p>
|
|
<hr/>
|
|
<ol>
|
|
<li>
|
|
<a class="el" href="JSModules.html#JSModulesRequire">require</a> </li>
|
|
</ol>
|
|
<hr/>
|
|
<p><a class="anchor" id="JSModulesRequire"></a> <hr/>
|
|
<code><b>require(<em>path</em>)</b></code><hr/>
|
|
<code>require</code> checks if the file specified by <em>path</em> has already been loaded. If not, the content of the file is executed in a new context. Within the context you can use the global variable <code>exports</code> in order to export variables and functions. This variable is returned by <code>require</code>.</p>
|
|
<p>Assume that your module file is <code>test1.js</code> and contains</p>
|
|
<div class="fragment"><pre class="fragment">exports.func1 = function() {
|
|
print("1");
|
|
};
|
|
|
|
exports.const1 = 1;
|
|
</pre></div><p>Then you can use <code>require</code> to load the file and access the exports.</p>
|
|
<div class="fragment"><pre class="fragment">> ./arangod --shell --startup.modules-path "/tmp/path1;/tmp/path2" /tmp/vocbase
|
|
ArangoDB shell [V8 version 3.6.5.1, DB version 1 (9727)]
|
|
|
|
arango> var test1 = require("test1");
|
|
|
|
arango> test1.const1;
|
|
1
|
|
|
|
arango> test1.func1();
|
|
1
|
|
</pre></div><p><code>require</code> follows the specification <a href="http://wiki.commonjs.org/wiki/Modules/1.1.1">Modules/1.1.1</a>. </p>
|
|
</div></div>
|
|
</div></body></html>
|