
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@netlify/functions
Advanced tools
@netlify/functions is an npm package that allows developers to create serverless functions that can be deployed on Netlify. These functions can handle HTTP requests, interact with APIs, and perform various backend tasks without the need for a dedicated server.
HTTP Request Handling
This feature allows you to handle HTTP requests and send responses. The code sample demonstrates a simple function that returns a 'Hello, World!' message.
const { Handler } = require('@netlify/functions');
const handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello, World!' })
};
};
module.exports = { handler };
Environment Variables
This feature allows you to access environment variables within your serverless functions. The code sample demonstrates how to read an environment variable and return its value in the response.
const { Handler } = require('@netlify/functions');
const handler = async (event, context) => {
const secret = process.env.SECRET_KEY;
return {
statusCode: 200,
body: JSON.stringify({ secret })
};
};
module.exports = { handler };
API Integration
This feature allows you to integrate with external APIs. The code sample demonstrates how to fetch data from an external API and return it in the response.
const { Handler } = require('@netlify/functions');
const fetch = require('node-fetch');
const handler = async (event, context) => {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
return {
statusCode: 200,
body: JSON.stringify(data)
};
};
module.exports = { handler };
AWS Lambda is a serverless computing service provided by Amazon Web Services. It allows you to run code without provisioning or managing servers. Compared to @netlify/functions, AWS Lambda offers more extensive integration with other AWS services but may require more configuration and setup.
Vercel (formerly known as Zeit Now) is a platform for serverless functions and static site hosting. It provides a similar serverless function capability as @netlify/functions but is tightly integrated with the Vercel platform. It offers easy deployment and scaling of serverless functions.
Firebase Functions is a serverless framework provided by Google Firebase. It allows you to run backend code in response to events triggered by Firebase features and HTTPS requests. Compared to @netlify/functions, Firebase Functions is more integrated with the Firebase ecosystem, making it a good choice for apps already using Firebase services.
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:
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 }
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!")
})
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
Please see CONTRIBUTING.md for instructions on how to set up and work on this repository. Thanks for contributing!
FAQs
TypeScript utilities for interacting with Netlify Functions
The npm package @netlify/functions receives a total of 1,088,865 weekly downloads. As such, @netlify/functions popularity was classified as popular.
We found that @netlify/functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 16 open source maintainers collaborating on the project.
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.