How to create serverless functions?
Add an api/ directory to any static Hodifly project and every JavaScript file in it becomes an HTTP endpoint under /api/ on your own domain.
Routing
One file, one URL. The file's path decides the endpoint:
File | URL |
|---|---|
|
|
|
|
|
|
Literal paths win over [bracket] parameters, and .js, .mjs and .cjs files all work. TypeScript and Python functions are not supported at this point: they answer 404, and the deploy log warns about them.
Writing a function
Both common handler styles are supported, in the same project if you like.
Classic signature (Express-like):
// api/hello.js
export default function handler(req, res) {
// req.query, req.body (JSON and form bodies are parsed), req.cookies
res.status(200).json({ hello: "world" });
}
Web standard signature:
// api/user/[id].js
export function GET(request) {
return Response.json({ ok: true });
}
module.exports = (req, res) => ..., per-method exports (GET, POST, ...) with automatic 405 for the rest, and export default { fetch(request) {...} } all work. Functions can import packages from your package.json: dependencies installed for the build are available at runtime.
Environment variables and secrets
The project's environment variables (Advanced settings, encrypted at rest, never sent to Hodi) are available in your functions as process.env.MY_VAR. This is the right place for API keys: function source is never served as a static file, and requesting a source path such as /api/hello.js answers 404.
Updated on: 27/07/2026
Thank you!