├── host.json ├── .funcignore ├── proxies.json ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── local.settings.json ├── tsconfig.json ├── BlobTrigger ├── function.json └── index.ts ├── HttpTrigger ├── function.json └── index.ts ├── HelloWorldNpm ├── function.json └── index.ts ├── extensions.csproj ├── package.json ├── .gitignore └── README.md /host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0" 3 | } 4 | -------------------------------------------------------------------------------- /.funcignore: -------------------------------------------------------------------------------- 1 | *.js.map 2 | *.ts 3 | .git* 4 | .vscode 5 | local.settings.json 6 | test 7 | tsconfig.json -------------------------------------------------------------------------------- /proxies.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/proxies", 3 | "proxies": {} 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-azuretools.vscode-azurefunctions" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /local.settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "IsEncrypted": false, 3 | "Values": { 4 | "AzureWebJobsStorage": "", 5 | "FUNCTIONS_WORKER_RUNTIME": "node" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "dist", 6 | "rootDir": ".", 7 | "sourceMap": true, 8 | "strict": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Attach to Node Functions", 6 | "type": "node", 7 | "request": "attach", 8 | "port": 9229, 9 | "preLaunchTask": "func: host start" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /BlobTrigger/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "name": "myBlob", 5 | "type": "blobTrigger", 6 | "direction": "in", 7 | "path": "samples-workitems/{name}", 8 | "connection": "AzureWebJobsStorage" 9 | } 10 | ], 11 | "scriptFile": "../dist/BlobTrigger/index.js" 12 | } 13 | -------------------------------------------------------------------------------- /BlobTrigger/index.ts: -------------------------------------------------------------------------------- 1 | import { AzureFunction, Context } from "@azure/functions" 2 | 3 | const blobTrigger: AzureFunction = async function (context: Context, myBlob: any): Promise { 4 | context.log("Blob trigger function processed blob \n Name:", context.bindingData.name, "\n Blob Size:", myBlob.length, "Bytes"); 5 | }; 6 | 7 | export default blobTrigger; 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "azureFunctions.projectRuntime": "~2", 3 | "azureFunctions.projectLanguage": "TypeScript", 4 | "azureFunctions.templateFilter": "Verified", 5 | "azureFunctions.deploySubpath": ".", 6 | "azureFunctions.preDeployTask": "prune", 7 | "files.exclude": { 8 | "obj": true, 9 | "bin": true 10 | }, 11 | "debug.internalConsoleOptions": "neverOpen" 12 | } 13 | -------------------------------------------------------------------------------- /HttpTrigger/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ], 19 | "scriptFile": "..\\dist\\HttpTrigger\\index.js" 20 | } 21 | -------------------------------------------------------------------------------- /HelloWorldNpm/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ], 19 | "scriptFile": "../dist/HelloWorldNpm/index.js" 20 | } 21 | -------------------------------------------------------------------------------- /extensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | 5 | ** 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /HelloWorldNpm/index.ts: -------------------------------------------------------------------------------- 1 | import { AzureFunction, Context, HttpRequest } from "@azure/functions" 2 | import { upper } from "case" 3 | 4 | const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise { 5 | context.log('HTTP trigger function processed a request.'); 6 | const name = req.query.name || (req.body && req.body.name) || "friend"; 7 | 8 | context.res = { 9 | // status: 200, /* Defaults to 200 */ 10 | body: upper(`Hello, ${name}!`) 11 | }; 12 | }; 13 | 14 | export default httpTrigger; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript-azure-functions", 3 | "description": "", 4 | "version": "0.1.0", 5 | "scripts": { 6 | "build": "tsc", 7 | "watch": "tsc -w", 8 | "prestart": "npm run build && func extensions install", 9 | "start:host": "func start", 10 | "start": "npm run start:host & npm run watch", 11 | "build:production": "npm run prestart && npm prune --production", 12 | "test": "echo \"No tests yet...\"" 13 | }, 14 | "dependencies": { 15 | "case": "^1.6.1" 16 | }, 17 | "devDependencies": { 18 | "@azure/functions": "^1.0.1-beta2", 19 | "typescript": "^3.3.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "func", 6 | "command": "host start", 7 | "problemMatcher": "$func-watch", 8 | "isBackground": true, 9 | "dependsOn": "npm: build" 10 | }, 11 | { 12 | "type": "npm", 13 | "script": "build", 14 | "dependsOn": [ 15 | "func: extensions install", 16 | "npm: install" 17 | ], 18 | "problemMatcher": "$tsc" 19 | }, 20 | { 21 | "type": "shell", 22 | "label": "prune", 23 | "command": "npm prune --production", 24 | "dependsOn": "npm: build", 25 | "problemMatcher": [] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /HttpTrigger/index.ts: -------------------------------------------------------------------------------- 1 | import { AzureFunction, Context, HttpRequest } from "@azure/functions" 2 | 3 | const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise { 4 | context.log('HTTP trigger function processed a request.'); 5 | const name = (req.query.name || (req.body && req.body.name)); 6 | 7 | if (name) { 8 | context.res = { 9 | // status: 200, /* Defaults to 200 */ 10 | body: "Hello " + (req.query.name || req.body.name) 11 | }; 12 | } 13 | else { 14 | context.res = { 15 | status: 400, 16 | body: "Please pass a name on the query string or in the request body" 17 | }; 18 | } 19 | }; 20 | 21 | export default httpTrigger; 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | .env.test 60 | 61 | # parcel-bundler cache (https://parceljs.org/) 62 | .cache 63 | 64 | # next.js build output 65 | .next 66 | 67 | # nuxt.js build output 68 | .nuxt 69 | 70 | # vuepress build output 71 | .vuepress/dist 72 | 73 | # Serverless directories 74 | .serverless/ 75 | 76 | # FuseBox cache 77 | .fusebox/ 78 | 79 | # DynamoDB Local files 80 | .dynamodb/ 81 | 82 | # Azure Functions artifacts 83 | bin 84 | obj 85 | appsettings.json 86 | local.settings.json 87 | 88 | # TypeScript output 89 | dist 90 | out 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Azure Functions ❤️'s TypeScript 2 | This is an example of a simple function app written in TypeScript. Most of the contents come from default templates that are available through both the [VS Code extension for Azure Functions](https://code.visualstudio.com/tutorials/functions-extension/getting-started) and [Azure Functions Core Tools](https://www.npmjs.com/package/azure-functions-core-tools). The `HelloWorldNpm` function is modified from a default template to import and use an npm module. 3 | 4 | ## Prerequisites 5 | - Install latest Active LTS version of [Node.js](https://nodejs.org) 6 | - Install latest [azure-functions-core-tools](https://www.npmjs.com/package/azure-functions-core-tools) if you do not already have it. 7 | - `npm install -g azure-functions-core-tools` 8 | - Run `npm install` from project root to install dev dependencies. 9 | 10 | ## The basics 11 | ### Build 12 | To build this Function app run `npm run build`. (Note that `npm start` and `F5` already include a build step.) If you are using binding extensions, the necessary binaries are also installed. 13 | 14 | On build, all TypeScript code in the root directory is transpiled into JavaScript and placed in an output directory called `dist`, as configured in `tsconfig.json` by `outDir`. We don't advise changing this configuration. The default [`scriptFile`](#using-scriptfile) property of each function assumes that the transpiled JavaScript output will be located in `dist` (example: `../dist/FunctionName/index.js`). 15 | 16 | ### Run 17 | To run your code, use `npm start`. If you are using VS Code, you can press `F5` to build and run instead. 18 | 19 | This command builds your Function app and starts the Azure Functions host to run your code. If you only want to run your built code, you can run `func start` or `npm run start:host`. 20 | 21 | ### Develop 22 | `npm run test` can be implemented to test your code. To ignore specific files and folders when deploying, add them to `.funcignore`. 23 | 24 | ### Deploy 25 | To prepare your function app for deployment, use `npm run build:production`. If you are using VS Code, deploy by clicking [`Deploy to Function App`](https://code.visualstudio.com/tutorials/functions-extension/deploy-app). If you already have a deployed Function app in Azure and want to update its contents, you can also use `func azure functionapp publish `. 26 | 27 | ## Learn More 28 | If you are getting started with Azure Functions, you can follow this tutorial to [create and deploy your first JavaScript function](https://docs.microsoft.com/azure/azure-functions/functions-create-first-function-vs-code). We recommend that you use Visual Studio Code and the [Azure Functions extension](https://code.visualstudio.com/tutorials/functions-extension/getting-started). 29 | 30 | The [Azure Functions developer guide](https://docs.microsoft.com/azure/azure-functions/functions-reference) and the [JavaScript-specific developer guide](https://docs.microsoft.com/azure/azure-functions/functions-reference-node) are good resources to gain an understanding of more Azure Functions concepts. 31 | --------------------------------------------------------------------------------