1
0
Fork 0
arangodb/Documentation/Books/Users/Foxx/DevelopingAnApplication.mdpp

82 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!CHAPTER Developing an Application
While developing a Foxx application, it is recommended to use the development
mode. The development mode makes ArangoDB reload all components of all Foxx
applications on every request. While this has a negative impact on performance,
it allows to view and debug changes in the application instantly. It is not
recommended to use the development mode in production.
During development it is often necessary to log some debug output. ArangoDB
provides a few mechanisms for this:
* using *console.log*:
ArangoDB provides the *console* module, which you can use from within your
Foxx application like this:
require("console").log(value);
The *console* module will log all output to ArangoDB's logfile. If you are
not redirecting to log output to stdout, it is recommended that you follow
ArangoDB's logfile using a *tail -f* command or something similar.
Please refer to [JSModuleConsole](../ModuleConsole/README.md) for details.
* using *internal.print*:
The *print* method of the *internal* module writes data to the standard
output of the ArangoDB server process. If you have start ArangoDB manually
and do not run it as an (unattended) daemon, this is a convenient method:
require("internal").print(value);
* tapping requests / responses:
Foxx allows to tap incoming requests and outgoing responses using the *before*
and *after* hooks. To print all incoming requests to the stdout of the ArangoDB
server process, you could use some code like this in your controller:
controller.before("/*", function (req, res) {
require("internal").print(req);
});
Of course you can also use *console.log* or any other means of logging output.
!SECTION Development Mode
If you start ArangoDB with the option *--javascript.dev-app-path* followed by
the path to an app directory (see below) and then the path to the database,
you are starting ArangoDB in development mode with the application loaded.
This means that on every request:
1. All routes are dropped
2. All module caches are flushed
3. Your manifest file is read
4. All files in your lib folder are loaded
5. An app in DIRNAME is mounted at */dev/DIRNAME*
6. The request will be processed
This means that you do not have to restart ArangoDB if you change anything
in your app. It is of course not meant for production, because the reloading
makes the app relatively slow.
The app directory has to be structured as follows:
```
└── databases
├── _system
│   ├── foxx_app_1
│   ├── foxx_app_2
│   └── foxx_app_3
└── my_db
   └── foxx_app_4
```
In this case you would have four foxx apps booted, three in the *_system* database
and one in the *my_db* database.
!SECTION Production Mode
To run a Foxx app in production first copy your app code to the directory given in
the config variable *--javascript.app-path*. After that use Foxx manager to mount the app.
You can also use Foxx manager to find out your current app-path.