TypeScript utilities for interacting with Netlify Functions
npm install @netlify/functions

JavaScript and TypeScript utilities for Netlify Functions.
```
npm install @netlify/functions
To use On-demand Builders, wrap your function handler with the builder function.
- With JavaScript:
`js
const { builder } = require('@netlify/functions')
const handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello World' }),
}
}
exports.handler = builder(handler)
`
- With TypeScript:
`ts
import { builder, Handler } from '@netlify/functions'
const myHandler: Handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello World' }),
}
}
const handler = builder(myHandler)
export { handler }
`
To use Scheduled Functions, wrap your function handler with the schedule function.
- With JavaScript:
`js
const { schedule } = require('@netlify/functions')
exports.handler = schedule('5 4 *', async () => {
console.log("It's 04:05 AM!")
})
`
- With TypeScript:
`ts
import { schedule } from '@netlify/functions'
export const handler = schedule('5 4 *', async () => {
console.log("It's 04:05 AM!")
})
`
This module exports typings for authoring Netlify Functions in TypeScript.
`ts
import { Handler } from '@netlify/functions'
const handler: Handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello World' }),
}
}
export { handler }
`
The following types are exported:
- HandlerHandlerCallback
- HandlerContext
- HandlerEvent
- HandlerResponse`
-
Please see CONTRIBUTING.md for instructions on how to set up and work on this repository. Thanks
for contributing!