-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |