Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Created April 10, 2019 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokawasa/ec7a036b6ef1f250703d20449c52ad08 to your computer and use it in GitHub Desktop.
Save yokawasa/ec7a036b6ef1f250703d20449c52ad08 to your computer and use it in GitHub Desktop.
Quickstart V2 Node.js Functions

Quickstart V2 Node.js Functions

Prerequisites

 $ node -v
 v11.1.11
 # Need to downgrade node version
 $ brew unlink node
 $ brew install node@10
 $ brew link node@10
 $ echo export PATH="/usr/local/opt/node@10/bin:$PATH" > ~/.bashrc

As explain in node version, 8.11.1 and 10.14.1 recommended

  • Install version 2.x of the Azure Functions Core Tools
# Linux & Windows
$ npm install -g azure-functions-core-tools

# Mac (Use brew, NOT npm)
$ brew tap azure/functions
$ brew install azure-functions-core-tools 

Create a NodeJS functions

Create a NodeJS functions project

$ func init nodejs --worker-runtime node

Create NodeJS functions from templates

List all NodeJS functions

$ func templates list

JavaScript Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Durable Functions activity
  Durable Functions HTTP starter
  Durable Functions orchestrator
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  IoT Hub (Event Hub)
  Azure Queue Storage trigger
  SendGrid
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  Timer trigger

Then, create a NodeJS function from templates

# First of all, move to NodeJS functions project top
$ cd nodejs

# Http Trigger functions
$ func new --language JavaScript --template "HTTP trigger" --name HttpTriggerJS

Run the function locally (Commandline)

Run the host. This automatically enables debugging with the Node port 5858:

$ func host start

# Test
$ curl --request POST http://localhost:7071/api/HttpTriggerJS --data '{"name":"Azure Rocks"}'

Run the function locally (VSCode)

The project needs to be ininitialized by VSCode

Local VSCode Configurations:

$ ls -1 .vscode

extensions.json
launch.json
settings.json
tasks.json

Issues

Issue: azure functions Mac issue You must have the Azure Functions Core Tools installed to debug your local functions.

brew tap azure/functions
brew install azure-functions-core-tools
brew link azure-functions-core-tools
# To relink
brew unlink azure-functions-core-tools && brew link azure-functions-core-tools

LINKS

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