1

I'm migrating my Node Express JS App to Azure functions. I've more than 250 Routes in my application. I went through this microsoft link to shift from Node Express JS to Azure functions (solution repo). What I understood is that I'll have to create azure functions for all the routes. i.e. each route will be a function in itself. I've more than 250 routes in my application so, I'll end up creating 250 function.js in their own folder, Is there a less painful way to make this migration.

I thought of doing code level routing based, i.e. grouping all API's by a common purpose and create functions for that top-level purpose and then internally route the request using URI passed to the function. Is there a better way to go about it?

Kid101
  • 1,440
  • 11
  • 25

1 Answers1

2

Eventually it might make more sense to create separate functions for benefits like better built-in logging and allow to leverage input/output bindings but would depend on your scenario.

But it is possible to reuse the express app code as is too, and there are two ways you could approach this

  1. A handler function to catch all routes and forward it to express. You could use the azure-function-express npm module which implements this for expressjs. Note that I haven't used this module myself but looks promising

  2. Leverage the Custom Handlers feature. This allows you to run any web server (the expressjs app in your case) and forward requests to the web server. Similarly to 1, you could choose to have just one catch all function since you have a lot of routes to cover.

    Note that this feature is currently in preview.

PramodValavala
  • 6,026
  • 1
  • 11
  • 30
  • The npm package you mentioned is not under development anymore and we are using Function V3 & Node V12 which isn't supported, moreover, we couldn't get it to work. so we ended up creating separate logical functions. yeah, it was painful. :) – Kid101 Oct 05 '20 at 12:31