# Run in debug and release mode

> The options of Total.run() choose between debug and release mode; read the mode from DEBUG and limit routes to one mode with @debug and @release.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 6b9c467dade4b69e103b12fa2687c66dae398141f5b622497f90a81bba6e01b9
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

Total.js runs in one of two modes, **debug** for development and **release** for the server, and the global boolean `DEBUG` tells your code which one is active. In debug mode the app runs under a file watcher that restarts it when you change a file, errors show details and source maps are generated. Release mode has no watcher and error pages without the technical details.

The mode is chosen by how the app is started, in the start script (`index.js`) that calls `Total.run(options)`:

- the default is debug, with the watcher;
- `options.release = true` starts release mode; the start script that Total.js generates sets it from the command line, so `node index.js --release` is the way to start production;
- `options.watcher = false` runs a single process without the watcher, and that is always release mode (it is what the examples of this cookbook use).

Before `Total.run()` has decided, `DEBUG` has a default taken from `NODE_ENV`: it is `false` when `NODE_ENV=production` and `true` otherwise. Code that runs at the moment a module is loaded sees that default, so do not rely on `NODE_ENV` for the final mode, only on `DEBUG` after the app has started.

The routes can follow the mode. The flag `@debug` makes a route exist only in debug mode and `@release` only in release mode; in the other mode the URL answers 404. Use `@debug` for tools you need while developing (a database viewer, a seed route) so they can never reach production by accident.

```js controllers/mode.js
exports.install = function() {
	ROUTE('GET /mode/', mode);
	ROUTE('GET /tools/ @debug', tools);
	ROUTE('GET /status/ @release', status);
};

function mode($) {
	$.json({ debug: DEBUG });
}

function tools($) {
	$.json({ tools: true });
}

function status($) {
	$.json({ status: 'ok' });
}
```
