Reputation: 2030
I am using VS code first time and trying to create a azure function with JavaScript language. I followed this article.
Environment:
Problem:
I created one sample azure function. When running the app with f5 it shows the following error
I removed extension bundle configuration from the host.json
and tried again. This time, I got the following error
Can anyone please help on me this
Update:
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node"
}
}
index.js
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));
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
}
Upvotes: 1
Views: 1807
Reputation:
Here is the workaround I did to run the Azure Functions of JavaScript Stack using Visual Studio Code by following the same documentation given in the question
Pre-requisites:
node -v
and npm -v
.Install the Azure Storage Emulator (it is deprecated but still using for local development and testing) from here by clicking on the standalone installer. -After Installing the Azure Storage Emulator, make sure it is running. If it is shutdown, then run it manually. To start the Azure Storage Emulator:
Azure Storage Emulator
.Start
> Enter and Close the Window.Install the Azure Functions Core Tools v3 as well as v4 used for both Old Version and New Version Stack Development from the source and check the version using func --versio
n command from command prompt.
Install the Azure CLI from the source and PowerShell Module from the source.
Follow this prerequisite check before going to the IDE (VS Code/Visual Studio).
Index.js
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));
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node"
}
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
host.json
To Run the Function, go to Run Menu > Select either of options Start Debugging
or Run without Debugging
and I have run this without starting the VS Code, it runs successful in locally.
Put a breakpoint at any line of the code and select the Start Debugging
option from the Run
Menu
Note:
For the errors like: A host error has occurred during startup operation
, Value cannot be null
, few resolution steps were:
AzureWebJobsStorage
is empty by default but if we're using the project locally, it is better to use like "AzureWebJobsStorage": "UseDevelopmentStorage=true"
You can download the above project from my GitHub Repository.
Upvotes: 1