# feathers-commands

> Create custom commands/routes for services beyond the 6 basic methods provided by FeathersJS

Latest version **0.1.4** (published 2018-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install feathers-commands
pnpm add feathers-commands
yarn add feathers-commands
bun add feathers-commands
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2018-07-27 |
| First published | 2018-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | danielkalen |
| Maintainers | danielkalen |
| Keywords | feathers, feathers-plugin |

## Links

- npm: https://www.npmjs.com/package/feathers-commands
- Repository: https://github.com/danielkalen/feathers-commands
- Homepage: https://github.com/danielkalen/feathers-commands#readme
- Issues: https://github.com/danielkalen/feathers-commands/issues
- npm.io page: https://npm.io/package/feathers-commands

## Dependencies (4)

- [smart-extend](https://npm.io/package/smart-extend.md) ^1.7.3
- [coffee-register](https://npm.io/package/coffee-register.md) ^2.0.0
- [@feathersjs/errors](https://npm.io/package/@feathersjs/errors.md) ^3.3.0
- [@feathersjs/commons](https://npm.io/package/@feathersjs/commons.md) ^1.4.1

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads
- [@react-md/material-icons](https://npm.io/package/@react-md/material-icons.md) — 1.6K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2018-07-27
- 0.1.3 — 2018-07-03
- 0.1.2 — 2018-06-14
- 0.1.1 — 2018-06-14
- 0.1.0 — 2018-05-17
- 0.0.2 — 2018-05-16
- 0.0.1 — 2018-05-10

## README

# feathers-commands

> Create custom commands/routes for services beyond the [6 basic methods](https://docs.feathersjs.com/guides/basics/rest.html#rest-and-services) provided by FeathersJS


## Install
```
$ npm install feathers-commands
```

## Usage
```js
const app = express(feathers())

// Register api
app.configure(require('feathers-commands'));

// Create service
app.use('myService', {
    get: (id)=> ...
    create: (data)=> ...
});

// Register commands
app.service('myService').command('sayHello/:title?', (data, params)=> {
    const title = params.title || 'Mr.';
    return Promise.resolve(`Hello to ${title} ${data.name}`);
});

app.service('myService').command('getStatus/:id', function(data, params) {
    return this.get(params.id).then (doc)=> doc.status
});
```

##### Running commands internally
```js
app.service('myService').run('sayHello', {name:'Daniel'});
app.service('myService').run('getStatus', null, {id:'abc123'});
```

##### Running commands via REST
```
POST /myService/sayHello => 'Hello to Mr. undefined'
POST /myService/sayHello/Mrs {"name":"Angela"} => 'Hello to Mrs. Angela'
POST /myService/getStatus/def456 => '<status>'
POST /myService/getStatus => 404 NOT FOUND
```

##### Hooks
Hooks will be invoked for custom commands just like they do for the [6 native methods](https://docs.feathersjs.com/guides/basics/rest.html#rest-and-services)
```js
app.service('myService').hooks({
    before: {
        all: ()=> console.log('all hook')
        getStatus: [
            ()=> console.log('1st specific hook')
            ()=> console.log('2nd specific hook')
        ]
    },
    after: {
        sayHello: ()=> console.log('3rd specific hook')
    }
})
```

##### `this` context
Commands will be invoked under the service context, meaning that `this` refers to the feathers-wrapped service object.

##### websocket support
Currently websocket transporters such as Primus and Socket.IO aren't directly supported. PRs are welcome.


## License
MIT © [Daniel Kalen](https://github.com/danielkalen)

---
_Source: https://npm.io/package/feathers-commands · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
