The app in this repo demonstrates the new Node.js HTTP streams feature on Azure Functions. It streams a large file (96mb by default) named temp/input.txt
to a file temp/output.txt
and logs the progress. This app has http streams turned on by default, but you can change this (and other settings) by modifying the src/constants.ts
file.
- Version 4.0.5530 of Azure Functions Core Tools
- Node.js v18+
-
Add a
local.settings.json
file with the following contents:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "", "FUNCTIONS_WORKER_RUNTIME": "node", "FUNCTIONS_REQUEST_BODY_SIZE_LIMIT": "4294967296" } }
-
Run
npm install
. -
Run
npm start
. This will build the app, create the large input file, and start the app. -
Leave the previous terminal running and open a new terminal to execute a function.
- If you want to simulate streaming a request, run
npm run streamRequest
. - If you want to simulate streaming a response, run
npm run streamResponse
.
- If you want to simulate streaming a request, run
-
You should see progress in the console as the file is processed. It happens fast for a 96mb file, but as long as you see a chunk count greater than 1, you know your data was streamed.
src/functions/*
: The actual functions for your appsrc/scripts/*
: Scripts used to create the large file and send requests to Azure Functionssrc/constants.ts
: A file with several settings that you can change to modify the behavior of the app.
We recommend you play around with this app to really get a feel for the feature!
- Follow the steps above to run your app.
- Open a new terminal and run
npm watch
. This will ensure your running app is updated every time you save a file. - Modify a setting in
src/constants.ts
, run the scripts mentioned above to simulate streaming a request or response, and see what happens!enableHttpStream
: Set this to false to turn the stream feature off. In general, you will notice slower performance and more errors with this feature off.sendRequestInChunks
: Set this to false to simulate different ways of sending a request to your app. The new streams feature will work regardless of how the request is sent, but without the new feature your app can fail in a variety of ways.inputFileSize
: Set this to a higher value to test the limits of your app. Each time you change this value, you will need to runnpm run createInputFile
to re-generate the input file with a different size.