Guide
Expose a Current‑Time REST Endpoint in Node‑RED: A Step‑by‑Step Guide
Learn how to create a lightweight REST API in Node‑RED that returns the server’s current time in JSON. Follow the prerequisites, wiring steps, verification commands, and troubleshooting tips to get a reliable /time endpoint.
Published by Tasadduq Burney
07 Aug 2026, 11:20 UTC
3 min136.1K views0

Goal
Expose a REST endpoint that, when called with GET /time, returns a JSON object containing the current server time in ISO‑8601 format. The endpoint should be reachable at http://localhost:1880/time by default.
Prerequisites
- Node‑RED runtime installed and running locally on the default port
1880. - Browser access to the Node‑RED editor (
http://localhost:1880). - Basic understanding of wiring nodes in Node‑RED.
- Optional:
curlinstalled for command‑line testing.
Step 1: Add an HTTP In Node
- Open the Node‑RED editor and drag an HTTP In node from the input palette onto the canvas.
- Double‑click the node to configure it:
- Method:
GET - URL:
/time - Name (optional):
GET /time - Click Done.
Step 2: Create a Function Node
- Drag a Function node onto the canvas and wire it from the
HTTP Innode. - Double‑click the Function node and paste the following code into the editor:
- Click Done.
msg.payload = {
time: new Date().toISOString()
};
return msg;
Step 3: Wire to an HTTP Response Node
- Drag an HTTP Response node onto the canvas and connect it to the Function node.
- Leave the default settings (Status Code 200) and click Done.
Step 4: Deploy and Test
- Click the Deploy button in the top right corner to activate the flow.
- Open a browser tab and navigate to
http://localhost:1880/time. You should see a JSON payload similar to: - Alternatively, run the following command in a terminal:
{
"time": "2026-09-16T12:34:56.789Z"
}
curl -i http://localhost:1880/time
Expected output:
| Status | Body |
|---|---|
| HTTP/1.1 200 OK | {"time":"2026-09-16T12:34:56.789Z"} |
Troubleshooting & Recovery
- Endpoint returns 500 Internal Server Error:
- Open the Node‑RED Debug panel and ensure the Function node’s output shows a valid object.
- Verify that the Function node’s code ends with
return msg;and thatmsg.payloadis set. - Check that the HTTP Response node is wired from the Function node; a missing connection will cause a 500.
- Review the console or
node-red-logfor stack traces.
- Port 1880 already in use:
- Stop the existing service or change Node‑RED’s listening port by editing
settings.js(e.g.,uiPort: 1881). - Restart Node‑RED and redeploy the flow.
- Stop the existing service or change Node‑RED’s listening port by editing
- Unexpected JSON format:
- Ensure the Function node’s code uses
msg.payload = { time: new Date().toISOString() };and not a string. - Check that no other nodes modify
msg.payloadbefore the HTTP Response node.
- Ensure the Function node’s code uses
Limitations & Best Practices
- Node‑RED is not intended for high‑performance, high‑concurrency APIs. For production workloads, consider a dedicated framework.
- Never expose sensitive data via this simple endpoint; sanitize any user input before including it in a payload.
- Keep the flow minimal; unnecessary nodes increase memory usage.
- Use the Node‑RED debug node sparingly in production to avoid large log files.
- Document the endpoint in your API reference for future maintainers.
Verification Checklist
- HTTP In node configured for
GET /time. - Function node returns an object with a
timekey. - HTTP Response node connected and not overridden by another node.
- Deploy button clicked and flow status shows green.
- curl or browser returns
200 OKand valid JSON. - Debug panel shows the payload object on each request.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.