Typescript starter for a timer-triggered (CRON job) Azure Function.
Motivation: I had some trouble setting up a local dev environment to run an Azure Function with a Timer trigger. Google and StackOverflow wisdom usually implies you're on Windows where Storage Emulator seems to be installed as part of a developer toolkit. On Mac and Linux it has to be installed; as well as some configuration has to be made.
The code in this repo is for a minimal function which is triggered every minute and prints the timer object passed by the Azure binding.
Typescript code is almost non-existent in the starter repo but I included linter and security check scripts as a best practice for the time when code grows.
- Node.js installed
- Brew installed (Mac)
Install the Azure Functions Core Tools (Mac)
brew tap azure/functions
brew install azure-functions-core-tools@3
Install npm dependencies
npm i
Install Azurite - an open-source Azure Storage Emulator, which is going to replace the Storage Emulator.
There are a few ways to install it:
Choose whichever works best for you. After installation you should have Azurite running locally and listening on a port.
For local development when using a storage emulator,
UseDevelopmentStorage=true
shortcut
can be used.
It lives in the git-ignored local.settings.json
:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
Start the function app locally. It will trigger the function according to the
schedule defined in cron-job/function.json
. Here we have 0 */1 * * * *
which
is at the top of every minute.
npm run start
Alternatively you can run/debug the function in VS Code, for that you'd need to install Azure Functions for Visual Studio Code
Make sure code has no syntax errors and is properly formatted. Make sure docs are valid Markdown.
npm run lint
Make sure there are no known vulnerabilities in dependencies.
npm run audit-security
This project is licensed under the MIT License - see the LICENSE file for details