Skip to content

Commit

Permalink
docs: Expand usage example and improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jackboberg committed Apr 21, 2017
1 parent 6c3047b commit a7e7d99
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions README.md
Expand Up @@ -20,54 +20,56 @@

## Usage

### `KnockKnock([commands], callback)`

- **commands** `Object` (Optional)
values are a command to execute, a trimmed `stdout` or `stderr` will be yielded
- **callback** `Function`
`(err, result) => {}`

#### default result

| key | value
| --- | ---
| name | derived from `package.json`
| version | derived from `package.json`
| env | `process.env.NODE_ENV`
| node | `node -v`
| npm | `npm -v`

### Examples

#### using defaults

```js
const KnockKnock = require('knock-knock')

KnockKnock((err, results) => {
if (err) throw err
console.log(results)
/** {
name: 'some-name',
version: '1.2.3',
env: 'production',
node: 'v6.10.1',
npm: '4.5.0'
} **/
})
```

Logs:

```json
{
name: 'some-name',
version: '1.2.3',
env: 'production',
node: 'v6.10.1',
npm: '4.5.0'
}
```

### pass custom commands
#### passing custom command

```js
const KnockKnock = require('knock-knock')

KnockKnock({ docker: 'docker -v' }, (err, results) => {
if (err) throw err
console.log(results)
// { docker: 'Docker version 17.03.1-ce, build c6d412e', ... }
})
```

Logs:

```json
{
name: 'some-name',
version: '1.2.3',
env: 'production',
node: 'v6.10.1',
npm: '4.5.0',
docker: 'Docker version 17.03.1-ce, build c6d412e'
}
```

### use as an API endpoint

#### Hapi
#### hapi endpoint

```js
const Hapi = require('hapi')
Expand All @@ -82,7 +84,7 @@ server.route([
])
```

#### Express
#### Express endpoint

```js
const Express = require('express')
Expand Down

0 comments on commit a7e7d99

Please sign in to comment.