首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用终端Visual在本地服务器上启动google云功能

无法使用终端Visual在本地服务器上启动google云功能
EN

Stack Overflow用户
提问于 2021-12-27 22:05:01
回答 1查看 789关注 0票数 2

我正在尝试开发我的第一个谷歌云功能,但希望在本地构建和测试。我以前没有这样做过,我只是在学习,所以请对我有耐心。

First --我创建了自己的moralisaccount目录,创建了带有默认信任的npm init的package.json,并用npm install @google-cloud/functions-framework安装了函数框架。

代码语言:javascript
复制
AMAC02CLCBTLEE:moralisaccount youthdev$ nvm use node
Now using node v17.3.0 (npm v8.3.0)
AMAC02CLCBTLEE:moralisaccount youthdev$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (moralisaccount) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/youthdev/MoralisAccount/package.json:

{
  "name": "moralisaccount",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) 
AMAC02CLCBTLEE:moralisaccount youthdev$  npm install @google-cloud/functions-framework

added 103 packages, and audited 104 packages in 4s

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
AMAC02CLCBTLEE:moralisaccount youthdev$ 

第二个-创建了一个简单的index.js文件,其函数位于与package.json相同的moralisaccount目录中。

代码语言:javascript
复制
/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */
 exports.moralisAccount = async (req, res) => {
    let message = req.query.message || req.body.message || 'Hello World!';
    res.status(200).send(message);
  };

最后一次--我在visual中的终端中运行了下面的代码,并且在终端中没有得到预期的响应。

实际

代码语言:javascript
复制
Node.js v17.3.0
youthdev@AMAC02CLCBTLEE moralisaccount % node node_modules/@google-cloud/functions-framework --target=moralisAccount
youthdev@AMAC02CLCBTLEE moralisaccount % 

预期:

代码语言:javascript
复制
Node.js v17.3.0
youthdev@AMAC02CLCBTLEE moralisaccount % node node_modules/@google-cloud/functions-framework --target=moralisAccount


Serving function...
Function: moralisAccount
URL: http://localhost:8080/

不知道在哪一步我搞砸了,因为我是个初学者。谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-28 04:21:53

试着按照下面的步骤使用链接,它可以正常工作。

https://github.com/GoogleCloudPlatform/functions-framework-nodejs

在您的场景中,不要运行node node_modules/@google-cloud/functions-framework --target=moralisAccount,而是尝试运行npx @google-cloud/functions-framework --target=moralisAccount

样本输出:

代码语言:javascript
复制
o@cloudshell:~/myapp/routes $ npx @google-cloud/functions-framework --target=helloWorld
Serving function...
Function: helloWorld
Signature type: http
URL: http://localhost:8080/

确保在您的index.js目录中运行该命令。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70500886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档