Serverless functions are written in JavaScript and use the NodeJS runtime. Use them to add new and advanced capabilities to HubSpot CMS websites.
application/json
when calling a function.429
response. The execution time of each function is included in the serverless function logs.
.functions
directory containing a JavaScript file, a serverless.json
configuration file, and a package.json
file. The .functions
directory can be named anything, as long as it contains the .functions
suffix. Files stored in this folder are not publicly accessible.
serverless.json
: the serverless function’s configuration file, which includes definitions for the function name, JavaScript file path, included secrets, and endpoint details..js
file: the code that gets executed when the function is invoked. This file can have any name, as long as it ends in .js
. You’ll specify the file name in the serverless.json
file.package.json
(project-based only): for serverless functions built with projects, this file configures dependencies needed to execute the function..functions
directory should be placed within the app directory, as shown below.
.functions
directory is uploaded directly to the design manager using the CLI, not through a developer project. The .functions
directory should contain a serverless.json
file and a JavaScript file containing the code to execute.
serverless.json
file. Learn more about managing secrets using the HubSpot CLI.console.log()
in your serverless function code for debugging purposes, then view its output in the function log details sidebar. Note that the message will not log directly to your browser console.
hs project logs
command. Learn more about using the hs project logs command.
There are two types of log messages produced:
2021-04-28T19:19:21.666Z - SUCCESS - Execution Time: 279ms
2021-04-28T19:15:13.200Z INFO Log some debug info
2021-04-28T19:15:14.200Z ERROR An error occurred
hs logs
command which gives you the ability to view your function’s logs. In addition to individual function invocation responses, time of execution, and execution time, any console.log
statement will also appear in function logs. Do not console.log
secrets like API keys.