Socket
Socket
Sign inDemoInstall

@netlify/functions

Package Overview
Dependencies
3
Maintainers
19
Versions
59
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @netlify/functions

JavaScript utilities for Netlify Functions


Version published
Weekly downloads
573K
decreased by-7.97%
Maintainers
19
Install size
243 kB
Created
Weekly downloads
 

Changelog

Source

2.6.0 (2024-02-13)

Features

  • publish ESM version (#473) (b1b7553)

Bug Fixes

  • deps: update dependency @netlify/serverless-functions-api to v1.13.1 (#462) (29b33ae)
  • deps: update dependency @netlify/serverless-functions-api to v1.14.0 (#470) (c77eb33)
  • skip purgeCache in local dev (#472) (9236053)

Readme

Source

functions

Build Node

JavaScript and TypeScript utilities for Netlify Functions.

Installation

npm install @netlify/functions

Usage

On-demand Builders

To use On-demand Builders, wrap your function handler with the builder function.

  • With JavaScript:

    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:

    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 }
    

Scheduled Functions (currently in beta)

To use Scheduled Functions, wrap your function handler with the schedule function.

  • With JavaScript:

    const { schedule } = require('@netlify/functions')
    
    exports.handler = schedule('5 4 * * *', async () => {
      console.log("It's 04:05 AM!")
    })
    
  • With TypeScript:

    import { schedule } from '@netlify/functions'
    
    export const handler = schedule("5 4 * * *", async () => {
      console.log("It's 04:05 AM!")
    })
    

TypeScript typings

This module exports typings for authoring Netlify Functions in TypeScript.

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:

  • Handler
  • HandlerCallback
  • HandlerContext
  • HandlerEvent
  • HandlerResponse

Contributors

Please see CONTRIBUTING.md for instructions on how to set up and work on this repository. Thanks for contributing!

FAQs

Last updated on 13 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc