Skip to content

Commit 0cab53f

Browse files
authored
Add instructions for local debugging (GoogleCloudPlatform#60)
* Add instructions for local debugging * Update README.md * Update README.md * Update README.md
1 parent 116314a commit 0cab53f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,35 @@ This directory contains advanced docs around the Functions Framework.
55
- TODO: Run Multiple Cloud Functions [#23](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/23)
66
- TODO: Pub/Sub Trigger [#37](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/37)
77
- TODO: Deploy to Cloud Run [#28](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/pull/28)
8-
- TODO: Local Debug [#15](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/15)
8+
9+
## Debugging functions
10+
11+
The Functions Framework works with standard tooling that you might use when writing a function for a Node.js environment. You can attach a debugger to your function by following these steps.
12+
13+
1. Write an `index.js` file containing your Node.js function:
14+
15+
```js
16+
exports.helloWorld = (req, res) => {
17+
res.send('Hello, World');
18+
};
19+
```
20+
21+
2. Install the Functions Framework:
22+
23+
```sh
24+
npm install @google-cloud/functions-framework
25+
```
26+
27+
3. Run `node`, enable the inspector and run the Functions Framework:
28+
29+
```sh
30+
node --inspect node_modules/@google-cloud/functions-framework --target=helloWorld
31+
...
32+
Debugger listening on ws://127.0.0.1:9229/5f57f5e9-ea4b-43ce-be1d-6e9b838ade4a
33+
For help see https://nodejs.org/en/docs/inspector
34+
Serving function...
35+
Function: helloWorld
36+
URL: http://localhost:8080/
37+
```
38+
39+
You can now use an IDE or other tooling to add breakpoints, step through your code and debug your function.

0 commit comments

Comments
 (0)