0

I am trying to create a simple hello world azure functions app using nodejs and express. But, i am getting the following error:

Exception while executing function: Functions.httpexpressapp. mscorlib: Unable to determine function entry point. If multiple functions are exported, you must indicate the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.

Here is my code:

function.json

 {
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "entryPoint": "index",
  "disabled": false
}

index.js:

const express = require('express')
const app = express()

app.get('/', (req, res) => res.send('Express JS Hello World App!!!'))

package.json:

{
  "name": "httpexpressapp",
  "version": "1.0.0",
  "description": "sample app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "john doe",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3"
  }
}

Then, i have a node_modules directory under the function app

Any help is appreciated. Thanks in advance!

3
  • Why do you think this is supposed to work? Commented Jul 3, 2018 at 21:34
  • @Mikhail it works on my local machine if it's a non function app, only difference is that i had an app.listen() in the index.js, i am new to both node and functions, so not sure what i am doing wrong. Do you know what i am doing wrong? Commented Jul 3, 2018 at 21:42
  • Functions expect you to export a function with specific signature. Follow the guide for your first function. Commented Jul 3, 2018 at 21:51

2 Answers 2

5

The Azure Functions platform is rather opinionated because of its ability to do things like bindings and Triggers. Functions coded in Node in Azure Functions need to be of the form.

module.exports = function(context) {
    // function logic goes here :)
};

You can find some JavaScript tips for Azure Functions here. It looks like you are trying to do a simple HTTP-trigger function. Looking at your example, you would want something like this.

module.exports = function(context, req) {
    context.res = {
        // status defaults to 200 */
        body: "Express JS Hello World App!!!"
    };
    context.done();
};

Note that Azure Functions will be handling the routing of your HTTP requests, so you wouldn't likely want to use Express.js.

Sign up to request clarification or add additional context in comments.

Comments

1

Even if you want to use the Express with the Azure function you can go for this Azure AWS serverless Express

package. Its very useful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.