Home > OS >  Respond a JSON object in Node.JS using Azure Function
Respond a JSON object in Node.JS using Azure Function

Time:01-07

I'm currently learning Azure Functions in my Back-end development. The problem is that using Azure Functions prevents my JavaScript code to return a simple JSON object in Postman. I've read the documentation and also tried using some JS functions like JSON.Stringify, but still no luck. Here's the sample of my code:

message = {
   success: true,
   status: 'pending',
   message: "Some message etc..."
}
return message;

I'm practically new to Azure, so any help will be appreciated. Thanks!

CodePudding user response:

Try this ...

// Construct response
const responseJSON = {
    "name": "Some name",
    "sport": "Some sport",
    "message": "Some message",
    "success": true
}

context.res = {
    // status: 200, /* Defaults to 200 */
    body: responseJSON,
    contentType: 'application/json'
};
  •  Tags:  
  • Related