# @google-cloud/functions-emulator 中文文档

规范地址：https://npmcn.com/package/%40google-cloud/functions-emulator/

版本：1\.0\.0-beta\.6
npm 元数据更新时间：2022-06-12T19:14:27.079Z
中文译文更新时间：2026-11-16T20:28:05.193Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40google-cloud/functions-emulator
原文对照：https://npmcn.com/package/%40google-cloud/functions-emulator/?lang=original
项目主页：https://github.com/GoogleCloudPlatform/cloud-functions-emulator#readme
源码仓库：https://github.com/GoogleCloudPlatform/cloud-functions-emulator

弃用说明：Deprecating in favor of the Functions Framework and firebase-tools\. See https://github\.com/googlearchive/cloud-functions-emulator/issues/327

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：237 kB，63 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：~6
- 运行依赖：20 个
- 首次发布：2016-10-24T17:41:13.437Z
- 最新版本发布：2019-04-18T19:49:30.630Z
- 近 30 天下载量：14563（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：42（近 12 个月 0 个）

## 中文简介

Google 云函数模拟器

## 安装

```sh
npm install @google-cloud/functions-emulator
```

也可以使用：`pnpm add @google-cloud/functions-emulator`、`yarn add @google-cloud/functions-emulator`、`bun add @google-cloud/functions-emulator`

## README

![Google Inc. logo](https://avatars2.githubusercontent.com/u/2810941?v=3&s=96 "Google")

# Google 云函数模拟器

[![NPM](https://img.shields.io/npm/v/@google-cloud/functions-emulator.svg?style=flat)](https://www.npmjs.org/package/@google-cloud/functions-emulator) [![Tests](https://img.shields.io/circleci/project/GoogleCloudPlatform/cloud-functions-emulator.svg)](https://circleci.com/gh/GoogleCloudPlatform/cloud-functions-emulator) [![Coverage](https://img.shields.io/codecov/c/github/GoogleCloudPlatform/cloud-functions-emulator/master.svg)](https://codecov.io/github/GoogleCloudPlatform/cloud-functions-emulator)

_免责声明:这不是Google官方产品._

**目录**

-   [什么是谷歌云函数模拟器??](https://npmcn.com/package/%40google-cloud/functions-emulator/#readme-what-is-the-google-cloud-functions-emulator)
-   [我怎么开始?](https://npmcn.com/package/%40google-cloud/functions-emulator/#readme-how-do-i-get-started)
-   [证件在哪里?](https://npmcn.com/package/%40google-cloud/functions-emulator/#readme-where-is-the-documentation)
    -   CLI 文档 : `functions --help`
    -   [如何向导](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/How-To-Guides)
-   [捐款](https://npmcn.com/package/%40google-cloud/functions-emulator/#readme-contributing)
-   [许可证](https://npmcn.com/package/%40google-cloud/functions-emulator/#readme-license)

## 什么是谷歌云函数模拟器??

这个 **Google 云函数模拟器** 是一个执行 Google Cloud 函数 API 的 Node.js 应用程序,包括一个CLI,您可以用它来管理应用程序.

模拟器允许您使用 [**部署**](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Deploying-functions), (中文(简体) ), [**运行**](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Calling-functions),以及 [**调试**](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Debugging-functions) 您的 Cloud 函数在您的本地机器上, 在应用到 Google Cloud 函数服务之前 .

### 说明

模拟器只支持节点 `v6.x.x`它确实 _没有_ 支持节点 `v8.x.x` 或作彼贤.

## 我怎么开始?

1.  写入函数 :
    
    ```
     mkdir helloWorld
     cd helloWorld
     touch index.js
     echo 'exports.helloWorld = (req, res) => res.send("Hello, World!");' > index.js
    ```
    
2.  安装模拟器 :
    
    国家预防机制:
    
    ```
     npm install -g @google-cloud/functions-emulator
    ```
    
    亚伦:
    
    ```
     yarn global add @google-cloud/functions-emulator
    ```
    
    或者在细节中读更多 [安装指令](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Installation)。 。 。 .
    
3.  启动模拟器 :
    
    ```
     functions start
    ```
    
4.  部署您的功能 :
    
    ```
     functions deploy helloWorld --trigger-http
    ```
    
    获取函数配置帮助 `functions deploy --help`。 。 。 .
    
5.  调用您的功能 :
    
    ```
     functions call helloWorld
    ```
    
6.  查看日志 :
    
    ```
     functions logs read
    ```
    

## 证件在哪里?

简而言之,模拟 CLI 是自我文档。 运行以下来获取 CLI 的帮助 :

```
functions --help
```

对于其他的一切,都可以看到 [如何向导](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/How-To-Guides)。 。 。 .

## 捐款

反馈、 报告错误或请求特性, 请 [打开一个问题](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues)。 。 。 .

为了促成改变, [检查贡献指南](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/.github/CONTRIBUTING.md)。 。 。 .

## 许可证

版权 2017, Google, Inc.

根据Apache 许可证颁发的许可证,2.0版本

见 [正式许可证](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/LICENSE)。 。 。 .

## 常见问题

### @google-cloud/functions-emulator 是什么？

Google 云函数模拟器注意：该包已被作者标记为弃用——Deprecating in favor of the Functions Framework and firebase-tools\. See https://github\.com/googlearchive/cloud-functions-emulator/issues/327

### 如何安装 @google-cloud/functions-emulator？

在项目目录运行 npm install @google-cloud/functions-emulator，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 functions、functions-emulator，可以用 npx functions 直接运行。

### @google-cloud/functions-emulator 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/google-cloud\_\_functions-emulator 是否存在。

### @google-cloud/functions-emulator 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @google-cloud/functions-emulator 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js ~6。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @google-cloud/functions-emulator 可以商用吗？

@google-cloud/functions-emulator 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @google-cloud/functions-emulator 的下载量有多少？

根据 npm 官方下载统计，@google-cloud/functions-emulator 在 2026/10/17 – 2026/11/15 这 30 天内被下载 14,563 次，日均约 485 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @google-cloud/functions-emulator 还在维护吗？

最新版本 1\.0\.0-beta\.6 发布于 2019/04/19（7 年前）；至今共发布 42 个版本，其中过去 12 个月发布了 0 个；首次发布于 2016/10/25。作者已将其标记为弃用，新项目建议寻找替代方案。

