DEV Community

Cover image for SERVERLESS AZURE
Habeeb Hameed
Habeeb Hameed

Posted on

SERVERLESS AZURE

๐Ÿš€ Deploying Azure Functions with JavaScript and Visual Studio Code

This tutorial walks through deploying a serverless function using Azure Functions, JavaScript, and Visual Studio Code. Screenshots are included for each step to guide you visually.


1. Install Azure Functions Core Tools

1. Install Azure Functions Core Tools

2. Install Azure Functions Extension in VS Code

2. Install Azure Functions Extension in VS Code

3. Create Azure Function Project

3. Create Azure Function Project

4. Select Manually Created Folder

4. Select Manually Created Folder

๐Ÿ› ๏ธ Step 5: Run and Test the Azure Function App Locally

After creating the project, paste this function code inside httpTrigger1.js:

const { app } = require('@azure/functions');

app.http('httpTrigger1', {
  methods: ['GET', 'POST'],
  authLevel: 'anonymous',
  handler: async (request, context) => {
    context.log(`Http function processed request for url "${request.url}"`);
    const name = request.query.get('name') || await request.text() || 'World';
    return { body: `Hello, ${name}!` };
  }
});
Enter fullscreen mode Exit fullscreen mode

Then:

i. Open a new terminal in VS Code: Ctrl + ~
ii. Run:

func start
Enter fullscreen mode Exit fullscreen mode

iii. Copy the localhost link shown, such as:

http://localhost:7071/api/httpTrigger1
Enter fullscreen mode Exit fullscreen mode

iv. Open it in your browser. Youโ€™ll see:

Hello, World!
Enter fullscreen mode Exit fullscreen mode

You can personalize the response:

http://localhost:7071/api/httpTrigger1?name=Dola
โ†’ Hello, Habeeb!
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ธ Screenshot:

http triger

6. Choose JavaScript and Run Locally

6. Choose JavaScript and Run Locally

7. Launch Local Function

7. Personalize it by changing the name in the script

8. Search for function app and create

8. Funtion app

9. After opening Azure and creating function app then consumption plan from the options

10. Choose Consumption Plan

10. Choose Consumption Plan

11. Input RG, Name, Region

11. Input RG, Name, Region

12. View App Overview

12. View App Overview

13. Publish App to Azure

Open your terminal in VS Code and run the following command to publish your Azure Function App:

func azure functionapp publish dolafuncapp

Enter fullscreen mode Exit fullscreen mode

13. Publish App to Azure

14. Verify Deployment in Azure

14. Refresh to open hhtp trigger

15. Copy the second link from Azure portal and lunch

15. Test Live Azure Function


โœ… Conclusion

You've successfully created and deployed an Azure Function using JavaScript and VS Code. You now know how to:

  • Create an Azure Function App
  • Run locally using VS Code
  • Publish to Azure
  • Access your function online

Top comments (0)