gcp-emulator v0.6.0
GCP Emulator
Roughly emulate Google Cloud Platform services for development.
Emulators
- Cloud Functions
cloud-functions
- Cloud Storage
cloud-storage
- Cloud Tasks
cloud-tasks
Getting Started
Install the package.
yarn add -D gcp-emulator
Use as a CLI.
gcp-emulator emulate --emulators cloud-functions --cloud-functions-filepath ./function.js
Use as a Library.
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.
CLI Usage
Options
Argument | Description | Value |
---|---|---|
--config | javascript or json config | .gcprc.js |
emulate
command
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 in Node.
{
[commandName]: {
[camelCaseArgument]: value;
}
}
Caveats & Limitations
The Cloud Functions emulator clears the 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 to stub the @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.