# @alicloud/fc

> Aliyun Function Compute API SDK

Latest version **1.2.3** (published 2017-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alicloud/fc
pnpm add @alicloud/fc
yarn add @alicloud/fc
bun add @alicloud/fc
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2017-10-12 |
| First published | 2017-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 130 |
| Author | Jackson Tian |
| Maintainers | chuck.ql, rockuw, humanhuang, jacksontian |

## Links

- npm: https://www.npmjs.com/package/@alicloud/fc
- Repository: https://github.com/aliyun/fc-nodejs-sdk
- Homepage: https://github.com/aliyun/fc-nodejs-sdk#readme
- Issues: https://github.com/aliyun/fc-nodejs-sdk/issues
- npm.io page: https://npm.io/package/@alicloud/fc

## Dependencies (4)

- [kitx](https://npm.io/package/kitx.md) ^1.2.0
- [debug](https://npm.io/package/debug.md) ^2.6.4
- [httpx](https://npm.io/package/httpx.md) ^2.1.1
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.23.0

## Recent versions

- 1.2.3 (latest) — 2017-10-12
- 1.2.2 — 2017-08-18
- 1.2.1 — 2017-08-02
- 1.2.0 — 2017-07-20
- 1.1.2 — 2017-06-16
- 1.1.1 — 2017-06-08
- 1.1.0 — 2017-05-27
- 1.0.2 — 2017-05-08
- 1.0.1 — 2017-05-08
- 1.0.0 — 2017-05-04

## README

fc-nodejs-sdk
=======

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![coverage][cov-image]][cov-url]

[npm-image]: https://img.shields.io/npm/v/@alicloud/fc.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@alicloud/fc
[travis-image]: https://img.shields.io/travis/aliyun/fc-nodejs-sdk/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/aliyun/fc-nodejs-sdk.svg?branch=master
[cov-image]: https://coveralls.io/repos/aliyun/fc-nodejs-sdk/badge.svg?branch=master&service=github
[cov-url]: https://coveralls.io/github/aliyun/fc-nodejs-sdk?branch=master

Documents: http://doxmate.cool/aliyun/fc-nodejs-sdk/api.html

## Install

```bash
npm install @alicloud/fc --save
```

## License

[MIT](LICENSE)

## Examples

### Promise

```js
'use strict';

var FCClient = require('@alicloud/fc');

var client = new FCClient('<account id>', {
  accessKeyID: '<access key id>',
  accessKeySecret: '<access key secret>',
  region: 'cn-shanghai',
  timeout: 10000 // Request timeout in milliseconds, default is 10s
});

var serviceName = '<service name>';
var funcName = '<function name>';

client.createService(serviceName).then(function(resp) {
  console.log('create service: %j', resp);
  return client.createFunction(serviceName, {
    functionName: funcName,
    handler: 'index.handler',
    memorySize: 128,
    runtime: 'nodejs4.4',
    code: {
      zipFile: fs.readFileSync('/tmp/index.zip', 'base64'),
    },
  });
}).then(function(resp) {
  console.log('create function: %j', resp);
  return client.invokeFunction(serviceName, funcName, 'event');
}).then(function(resp) {
  console.log('invoke function: %j', resp);
}).catch(function(err) {
  console.error(err);
});
```

### async/await (node >= 7.6)

```js
'use strict';

const FCClient = require('@alicloud/fc');

var client = new FCClient('<account id>', {
  accessKeyID: '<access key id>',
  accessKeySecret: '<access key secret>',
  region: 'cn-shanghai',
});

var serviceName = '<service name>';
var funcName = '<function name>';

async function test () {
  try {
    var resp = await client.createService(serviceName);
    console.log('create service: %j', resp);

    resp = await client.createFunction(serviceName, {
      functionName: funcName,
      handler: 'index.handler',
      memorySize: 128,
      runtime: 'nodejs4.4',
      code: {
        zipFile: fs.readFileSync('/tmp/index.zip', 'base64'),
      },
    });
    console.log('create function: %j', resp);

    resp = await client.invokeFunction(serviceName, funcName, 'event');
    console.log('invoke function: %j', resp);
  } catch (err) {
    console.error(err);
  }
}

test().then();
```

### Custom headers

```js
await client.invokeFunction(serviceName, funcName, 'event', {
  'x-fc-invocation-type': 'Async'
});
```

## API Spec

See: https://help.aliyun.com/document_detail/52877.html

## Test

```sh
ACCOUNT_ID=<ACCOUNT_ID> ACCESS_KEY_ID=<ACCESS_KEY_ID> ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET> make test
```

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