Skip to content

Commit

Permalink
docs: Add programmatically section
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Mar 9, 2018
1 parent f765a53 commit 7e4c9d5
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion docs/mono.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
# Use programmatically

_Coming soong_
Mono can be used programmatically, it's really useful when integrating it with tools like [PM2](https://github.com/Unitech/pm2), [New Relic]() and more.

Let's see what mono `exposes` as default:

```js
const mono = require('@terrajs/mono')
```

Definition:

```js
mono(dir?: string): Promise<context>
```

> `dir` is optional, it's where you want mono to start, it will look from `<dir>/conf/`, `<dir>/src/` and `<dir>/package.json`.
The context is an `object` with some useful properties:

- `server`: The node.js server created
- `app`: The Express.js app instance
- `conf`: Application configuration object, see [configuration](/configuration)
- `log`: Log instance, see [logging](/logging)
- `hook`: Mono hook instance, see [hooks](/hooks)

Example `server.js`:

```js
const mono = require('@terrajs/mono')

mono(__dirname)
.then((context) => {
console.log('Mono ready!')
})
.catch((err) => {
console.error(err)
})
```

Then you can run Mono by running `node server.js`.

0 comments on commit 7e4c9d5

Please sign in to comment.