Azure Functions documentation

Create your first Azure Function using Visual Studio Code

This tutorial walks you through creating, testing, and deploying a simple HTTP‑triggered Azure Function using Visual Studio Code.

Prerequisites

Step 1 – Create a new Function project

mkdir MyFirstFunction
cd MyFirstFunction
func init . --worker-runtime node --language javascript

Step 2 – Add an HTTP trigger

func new --template "HTTP trigger" --name HttpExample

When prompted, select JavaScript as the language and accept the default authorization level (Function).

Step 3 – Review the generated code

Open HttpExample/index.js in VS Code. The function looks like this:

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    const name = (req.query.name || (req.body && req.body.name));
    if (name) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello, " + name
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
};

Step 4 – Run the function locally

func start

When the runtime starts, you’ll see a URL similar to:

http://localhost:7071/api/HttpExample?name=World

Open that URL in a browser – you should see Hello, World.

Step 5 – Deploy to Azure

  1. Log in to Azure CLI and set your subscription.
  2. Create a Function App in a resource group (replace placeholders):
az group create --name MyResourceGroup --location eastus
az storage account create --name mystorageacct123 --location eastus --resource-group MyResourceGroup --sku Standard_LRS
az functionapp create --resource-group MyResourceGroup --consumption-plan-location eastus --runtime node --runtime-version 18 --functions-version 4 --name MyFirstFunctionApp --storage-account mystorageacct123
  1. Deploy using the Core Tools:
func azure functionapp publish MyFirstFunctionApp

Step 6 – Test the deployed function

Navigate to the Function App in the Azure portal, copy the function URL, append ?name=Azure, and browse to it. You should receive Hello, Azure.

Next steps