Skip to content

Instantly share code, notes, and snippets.

@christopheranderson
Last active January 13, 2017 20:34
Show Gist options
  • Save christopheranderson/f428d84047eb331ad34499476554d156 to your computer and use it in GitHub Desktop.
Save christopheranderson/f428d84047eb331ad34499476554d156 to your computer and use it in GitHub Desktop.
How to debug Node Azure Functions locally

How to debug Node Azure Functions locally

This is a guide on how to set up the Azure Functions CLI to debug functions locally.

🚧 WARNING - This is very experimental and not yet very easy. I'm writing up this guide for the brave few. WARNING 🚧

🐲 Beyond here be dragons. 🐲

Requirements

  1. Windows only for now (Need to move to dotnet core)
  2. Node v5.9.1
  3. VS Code
  4. A saint's patience (as in, you may need a stiff drink)

I also use PowerShell for certain things, but not a requirement.

Set up steps

  1. Install the Azure Functions CLI - npm i -g azurefunctions
  2. Set an environment variable to enable debuging - $env:EDGE_NODE_PARAMS = '--debug'
  3. Get a demo node function set up.
    • I recommend HTTP since it doesn't require a Storage Account secret being set up.
    • Use the func new to set it up (which uses our awesome yeoman generator)
  4. Test it with func run ./<function name>

Attaching a debugger with VS Code

  1. Create a launch.json file from your debug window in VS Code

  2. Edit the config to:

{ "version": "0.2.0", "configurations": [ { "name": "Attach to Process", "type": "node", "request": "attach", "processId": "", "port": 5858, "sourceMaps": false, "outDir": null } ] } ``` 3. Edit the PID to be the PID of your Node process executing your Function. (The host has to be up!) - You can find the PID with tasklist /FI "IMAGENAME eq node.exe" - If you see more than one in that list, it's pretty much best guess, as far as I can tell. :(

Assuming you chose wisely, you're able to cross the bridge and start debugging your code! Works fairly well once you get over the set up steps.

We'll work hard on making that experience smoother before we move the CLI to "beta" in next month or so.

Known issues

  • Node inspector did not like me tonight - it was crashing in the v8-debug module
@joshgav
Copy link

joshgav commented Jan 13, 2017

Would be good to test with type:"node2" as the debugger, with node --inspect and with port 9229. That's the new Node.js debugging interface, the old one is going away soon.

See https://code.visualstudio.com/docs/editor/node-debugging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment