'NodeJS/Express.js - Response contains different values each time after GET request
My goal is to develop a RESTful API with Express.js where a runtime parameter can be read-out and reset with HTTP methods. But I observe that the response values are not consistent.
I have tried to write the code which creates the inconsistency in the responses.
const express = require("express");
const app = express();
let init = 0;
let runtime = init;
setInterval( () => {
runtime++;
}, 1000); // raise runtime value every 1000 ms
app.get("/runtime", (req, res) => {
res.end(JSON.stringify(runtime))
});
app.post("/runtime", (req, res) => {
runtime = init;
res.end(JSON.stringify({"runtime": "reset to init"}))
});
In localhost, everything works fine line this:
Get /runtime : 1
Get /runtime : 2
Get /runtime : 3
Get /runtime : 4
Get /runtime : 5
…
As a deployed app (to AWS in a corporate environment), the inconsistency starts: After sending the post-method, I receive different values in the response to GET /runtime, the values. E.g. "12 s", then "9 s", then "14 s" then "12 s", so as if I was tapping into two different parameter values like runtime 1 and runtime 2:
Get /runtime : 1
Get /runtime : 2
Get /runtime : 3
Post /runtime : ok
Get /runtime : 5
Get /runtime : 1
Get /runtime : 7
Get /runtime : 3
Get /runtime : 9
Get /runtime : 5
…
Happy about every hint about why this observation occurs.
Thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
