-
Notifications
You must be signed in to change notification settings - Fork 115
Debugging with Visual Studio Code
Table of Contents
One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile and debug loop.
Each deployed function has its own worker process, separate from the main Emulator process. This is more secure and safer for the Emulator and simulates production, but it means there's a different debugger running for each deployed function.
For more information on the standard Node.js Debugger, see Node.js Debugger.
-
Open Visual Studio Code in your project folder.
-
Create a new launch configuration (in the
launch.json
file) for your project:{ "version": "0.2.0", "configurations": [ { "name": "Debug Function", "type": "node", "request": "attach", "port": 5858 } ] }
Be sure to set
type
tonode
. -
Open the file that you want to debug and set a breakpoint by clicking to the left of the line number of the line where you want to set the breakpoint.
-
Deploy the function you want to debug, e.g.:
functions deploy helloWorld --trigger-http
See Deploying functions.
-
To debug a function using the standard Node.js debugger, run the following:
functions debug helloWorld
You should see something like the following printed to the console:
Debugger for helloWorld listening on port 5858.
You can also configure the Debugger's port and/or force the function to pause execution until you attach to the Debugger. Run
functions debug --help
for details. -
In Visual Studio Code, go to the Debug View and select your "Debug Function" launch configuration.
-
Click the green arrow button to attach to the debugger and start debugging.
-
Call your function to start debugging it, seen below:
-
When you're done, click the red "Disconnect" button to disconnect from the debugger.
-
To take your function out of debug mode, run the following:
functions reset helloWorld
or to restart the function and keep its debugging settings, run the following:
functions reset helloWorld --keep
Run
functions debug --help
for details.
For more information on the new Node.js V8 Inspector integration, see Node.js V8 Inspector integration. See also Debugging with Chrome DevTools.
-
Open Visual Studio Code in your project folder.
-
Create a new launch configuration (in the
launch.json
file) for your project:{ "version": "0.2.0", "configurations": [ { "name": "Inspect Function", "type": "node2", "request": "attach", "port": 9229 } ] }
Be sure to set
type
tonode2
. -
Open the file that you want to debug and set a breakpoint by clicking to the left of the line number of the line where you want to set the breakpoint.
-
Deploy the function you want to debug, e.g.:
functions deploy helloWorld --trigger-http
See Deploying functions.
-
To inspect a function using the new Node.js V8 Inspector integration, run the following:
functions inspect helloWorld
You should see something like the following printed to the console:
Debugger for helloWorld listening on port 9229.
You can also configure the Debugger's port and/or force the function to pause execution until you attach to the Debugger. Run
functions inspect --help
for details. -
In Visual Studio Code, go to the Debug View and select your "Inspect Function" launch configuration.
-
Click the green arrow button to attach to the debugger and start debugging.
-
Call your function to start debugging it, seen below:
-
When you're done, click the red "Disconnect" button to disconnect from the debugger.
-
To take your function out of debug mode, run the following:
functions reset helloWorld
or to restart the function and keep its debugging settings, run the following:
functions reset helloWorld --keep
Run
functions reset --help
for details.
Disclaimer: This is not an official Google product.
@google-cloud/functions-emulator is currently in pre-1.0.0 development. Before the 1.0.0 release, backwards compatible changes and bug fixes will bump the patch version number and breaking changes will bump the minor version number.