无法使用终端 Visual Studio 在本地服务器上启动 google 云功能
Not able to start google cloud function on local server with terminal Visual Studio
我正在尝试开发我的第一个 Google Cloud Function,但想在本地构建和测试。我以前没有这样做过,我只是在学习所以请耐心等待。
首先 - 我创建了我的 moralisaccount
目录,使用默认配置创建了 package.json 和 npm init
,并安装了函数框架npm install @google-cloud/functions-framework
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$
第二个 - 在与我的 package.json
相同的 moralisaccount 目录中创建了具有简单功能的简单 index.js 文件
/**
* 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);
};
Last - 我 运行 在 visual studio 内的终端下面,但我没有在终端内得到预期的响应。
实际
Node.js v17.3.0
youthdev@AMAC02CLCBTLEE moralisaccount % node node_modules/@google-cloud/functions-framework --target=moralisAccount
youthdev@AMAC02CLCBTLEE moralisaccount %
预计:
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/
作为初学者,我不确定在哪一步搞砸了。感谢您的帮助!
尝试按照下面的步骤操作 link,效果很好。
https://github.com/GoogleCloudPlatform/functions-framework-nodejs
在你的场景中,而不是 运行ning node node_modules/@google-cloud/functions-framework --target=moralisAccount
尝试 运行ning npx @google-cloud/functions-framework --target=moralisAccount
示例输出:
o@cloudshell:~/myapp/routes $ npx @google-cloud/functions-framework --target=helloWorld
Serving function...
Function: helloWorld
Signature type: http
URL: http://localhost:8080/
确保 运行 您的 index.js
目录中的命令。
我正在尝试开发我的第一个 Google Cloud Function,但想在本地构建和测试。我以前没有这样做过,我只是在学习所以请耐心等待。
首先 - 我创建了我的 moralisaccount
目录,使用默认配置创建了 package.json 和 npm init
,并安装了函数框架npm install @google-cloud/functions-framework
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$
第二个 - 在与我的 package.json
相同的 moralisaccount 目录中创建了具有简单功能的简单 index.js 文件/**
* 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);
};
Last - 我 运行 在 visual studio 内的终端下面,但我没有在终端内得到预期的响应。
实际
Node.js v17.3.0
youthdev@AMAC02CLCBTLEE moralisaccount % node node_modules/@google-cloud/functions-framework --target=moralisAccount
youthdev@AMAC02CLCBTLEE moralisaccount %
预计:
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/
作为初学者,我不确定在哪一步搞砸了。感谢您的帮助!
尝试按照下面的步骤操作 link,效果很好。
https://github.com/GoogleCloudPlatform/functions-framework-nodejs
在你的场景中,而不是 运行ning node node_modules/@google-cloud/functions-framework --target=moralisAccount
尝试 运行ning npx @google-cloud/functions-framework --target=moralisAccount
示例输出:
o@cloudshell:~/myapp/routes $ npx @google-cloud/functions-framework --target=helloWorld
Serving function...
Function: helloWorld
Signature type: http
URL: http://localhost:8080/
确保 运行 您的 index.js
目录中的命令。