A Tiny HTTP “Hello”
Using only Node.js, we spin up a tiny HTTP “Hello” response in the serverless style.
Pattern: export a handler(event, context); the platform gives you event/context and expects a response.
xxxxxxxxxx22
// A minimal serverless-style handler and a local driver (no frameworks).// "Handler" style function the platform would call:async function handler(event, context) { // event: request data (path, query, body), context: metadata (request id, deadline) return { statusCode: 200, headers: { "content-type": "application/json" }, body: JSON.stringify({ message: "Hello, Serverless!", time: new Date().toISOString() }) };}// Local driver to simulate a single invocation:if (require.main === module) { const fakeEvent = { path: "/hello", queryStringParameters: { name: "Ana" } }; const fakeContext = { requestId: "req-123", deadlineMs: Date.now() + 3000 }; handler(fakeEvent, fakeContext).then(res => { console.log("RESPONSE:", res); });}module.exports = { handler };OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment


