# gcp-emulator

> Emulate Google Cloud Platform services

Latest version **0.6.0** (published 2020-05-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install gcp-emulator
pnpm add gcp-emulator
yarn add gcp-emulator
bun add gcp-emulator
```

Provides the command `gcp-emulator`.

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2020-05-08 |
| First published | 2020-04-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 67.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 8eecf0d2 |
| Maintainers | 8eecf0d2 |

## Links

- npm: https://www.npmjs.com/package/gcp-emulator
- Repository: https://github.com/8eecf0d2/gcp-emulator
- Homepage: https://github.com/8eecf0d2/gcp-emulator#readme
- Issues: https://github.com/8eecf0d2/gcp-emulator/issues
- npm.io page: https://npm.io/package/gcp-emulator

## Dependencies (8)

- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [ngrok](https://npm.io/package/ngrok.md) ^3.2.7
- [sinon](https://npm.io/package/sinon.md) ^9.0.2
- [express](https://npm.io/package/express.md) ^4.17.1
- [commander](https://npm.io/package/commander.md) ^5.0.0
- [superagent](https://npm.io/package/superagent.md) ^5.2.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [@google-cloud/tasks](https://npm.io/package/@google-cloud/tasks.md) ^2.0.0

## Recent versions

- 0.6.0 (latest) — 2020-05-08
- 0.5.1 — 2020-05-07
- 0.5.0 — 2020-05-07
- 0.4.0 — 2020-05-06
- 0.3.1 — 2020-05-06
- 0.3.0 — 2020-05-05
- 0.2.1 — 2020-04-22
- 0.2.0 — 2020-04-22
- 0.1.0 — 2020-04-16

## README

# GCP Emulator

[![Test](https://github.com/8eecf0d2/gcp-emulator/workflows/Test/badge.svg)](https://github.com/8eecf0d2/gcp-emulator/actions?query=workflow%3ATest)
[![Release](https://github.com/8eecf0d2/gcp-emulator/workflows/Release/badge.svg)](https://github.com/8eecf0d2/gcp-emulator/actions?query=workflow%3ARelease)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=8eecf0d2/gcp-emulator)](https://dependabot.com)

Roughly emulate Google Cloud Platform services for development.

## Emulators

 - [x] Cloud Functions `cloud-functions`
 - [x] Cloud Storage `cloud-storage`
 - [x] Cloud Tasks `cloud-tasks`

## Getting Started

Install the package.
```bash
yarn add -D gcp-emulator
```

Use as a CLI.
```bash
gcp-emulator emulate --emulators cloud-functions --cloud-functions-filepath ./function.js
```

Use as a Library.
```typescript
import { EmulatorCloudFunctions } from "gcp-emulators";

const emulatorCloudFunctions = new EmulatorCloudFunctions({
  filepath: "./function.js",
  server: {
    port: 9010,
    hostname: "localhost",
    ssl: ...,
  },
});
```

## Logging

The logger supports the following types of logs `*, info, warn, error`.

You can configure which types of logs are output by setting the `LOGGER` environment variable or setting the `UtilityLogger.level` property.

## Proxy

You can configure a proxy server for all http based emulators to use.

You can also configure the proxy to use [ngrok](https://ngrok.com/).

## CLI Usage

#### Options

| Argument | Description | Value |
|----------|-------------|-------|
| `--config` | javascript or json config | `.gcprc.js` |


### `emulate` command

```bash
gcp-emulator emulate [options]
```

#### Options

| Argument | Description | Value |
|----------|-------------|-------|
| `--emulators` | emulators to use | `cloud-functions,cloud-storage,cloud-tasks` |
| `--proxy` | proxy emulators | `true` |
| `--proxy-port` | proxy server port | `9000` |
| `--proxy-ngrok` | proxy with ngrok | `true` |
| `--proxy-ngrok-authtoken` | proxy ngrok authtoken | `xxx` |
| `--proxy-ngrok-subdomain` | proxy ngrok subdomain | `gcp-emulator` |
| `--ssl-key-filepath` | global server ssl key path | `./key.pem` |
| `--ssl-cert-filepath` | global server ssl cert path | `./cert.pem` |
| `--cloud-functions-port` | cloud-functions emulator server port | `9010` |
| `--cloud-functions-filepath` | cloud-functions emulator source path | `./function.js` |
| `--cloud-functions-ssl-key-filepath` | cloud-functions emulator server ssl key path | `./key.pem` |
| `--cloud-functions-ssl-cert-filepath` | cloud-functions emulator server ssl cert path | `./cert.pem` |
| `--cloud-storage-port` | cloud-storage emulator server port | `9020` |
| `--cloud-storage-filepath` | cloud-storage emulator source path | `./public` |
| `--cloud-storage-ssl-key-filepath` | cloud-storage emulator server ssl key path | `./key.pem` |
| `--cloud-storage-ssl-cert-filepath` | cloud-storage emulator server ssl cert path | `./cert.pem` |

## CLI Config

The file provided to the `--config` argument should return the following Javascript object structure when [required](https://nodejs.org/api/modules.html#modules_require_id) in Node.

```javascript
{
  [commandName]: {
    [camelCaseArgument]: value;
  }
}
```

## Caveats & Limitations

The **Cloud Functions** emulator clears the [require.cache](https://nodejs.org/api/modules.html#modules_require_cache) before executing the function, this improves the development experience but may cause issues of it's own in certain situations.

The **Cloud Storage** emulator is _more-or-less_ a simple static server.

The **Cloud Tasks** emulator uses [sinon](http://npmjs.com/package/sinon) to stub the [@google-cloud/tasks](https://www.npmjs.com/package/@google-cloud/tasks) package so it is required for the emulator to operate.

Depending on your usage a built-in 404 page will be sent to requests that cannot be resolved to an emulator, or where an emulator cannot resolve the request, this does not align with any particular Google Cloud Platform service but seems more useful than not having it.

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