Tonto.js: Apache Config File Generator
Last updated 7 years ago .
· Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install tonto 
SYNC missed versions from official npm registry.
 _____ ___  _  _ _____ ___
|_   _/ _ \| \| |_   _/ _ \
  | || (_) | .` | | || (_) |
  |_| \___/|_|\_| |_| \___/.JS

NPM version Build Status Coverage Status Code Climate

Dependency Status Dev Dependency Status


This library helps with automating the generation of Apache web server configuration files. It provides a native camelCased javascript function API which support all native (and native mod) configuration directives from Apache versions 2.4, 2.2, and 2.0:

Additionally, Tonto is easily configured at instantiation to support any custom directive that you may have, (such as 3rd-party mod directives like 'PassengerRoot').

The Name "Tonto"

This library is named after the Tonto (Dilzhę́’é) people, who are one of the Western Apache groups in North America.

Long ago, their enemies called them "foolish", "wild", "crazy", and "those who you don't understand" for speaking and doing things differently than their neighbors. Today, they are known throughout the art communities for their superior fine crafts.


Use NPM to install the tonto package into your node.js project:

$ npm install tonto --save

Getting Started

1. Each instance of Tonto is a version-specific apache config document object that you add directives to by calling it's directive functions:

var tonto = new Tonto('2.4');

2. There are solo directive functions that take a single value argument, and block directive functions which take a sub-directive setter object as the second argument:

tonto.virtualHost('*:80', function (subDirectiveDocument) {
  // Here, you can call any directive function directly on subDirectiveDocument, and it will be added as a sub-directive.

3. When the document object has all directives added to it, you can render the document to string by calling:


4. All directives are chainable:

var renderedDocument = tonto
  .loadModule('some_module /some/path/to/')

Directive Functions

Specifying an Apache Version

Tonto.js comes with built-in support for all native (and native mod) directives in versions 2.4, 2.2, and 2.0. Additionally, you can specify any number of extra directives.

You specify which version you want to use during instantiation of the constructor:

var twoFour = Tonto('2.4');
Object.keys(twoFour).length; // 594

var twoTwo = Tonto('2.2');
Object.keys(twoTwo).length; // 419

var twoZero = Tonto('2.0');
Object.keys(twoZero).length; // 364

Directive/Function Case Differences

Whereas Apache directives are typed in TitleCase, tonto converts each of the directives into camelBackCase named functions.

For example:

  • LoadModule is added to the document with: .loadModule('some_module /some/path/to/')
  • SSLCertificateKeyFile is added to the document with: .sslCertificateKeyFile('/some/path/to/some_key.pem')
  • VirtualHost is added to the document with: .virtualHost('*:80', subDirectiveSetter)

Sub-Directive Setter

Block directives require a function as the second argument. This function has one argument itself, which is a clean sub-document. You can call any directive from the main document on a sub-document.

Here is an example of a sub-directive setter defined as a named function:

tonto.virtualHost('*:80', subDirectiveSetter);

function subDirectiveSetter(subDirectives) {

This example will render:

<VirtualHost *:80>

Defining Custom Directives

If you are using a 3rd party mod that provides custom directives, there is an easy way to extend tonto.js with custom functions for this purpose:


tonto.customDirective('some value'); // Solo directive

tonto.customBlock('some value', function (subDirectives) {
  // Because CustomBlock is surrounded in < and >, it is processed as a block directive

Current Tags

  • 0.1.1                                ...           latest (7 years ago)

8 Versions

  • 0.0.0                                ...           8 years ago
  • 0.0.1                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.5                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
Maintainers (2)
Dependencies (4)
Dev Dependencies (9)

Copyright © | 浙ICP备15033595号-63 |