In my ExpressJS application, I have created an endpoint that needs to proxy a large raw binary to a remote backend REST service without storing anything in memory.
To achieve this, I initially looked into using the request module with code like:
req.pipe(request({method: "POST"}))
However, since the request library is deprecated, I switched to using fetch. Here's what I have so far:
app.post("/my-endpoint", async (req, res) => {
try {
const url = http://link-to-backend.com/
const response = await fetch(url, {
method: "POST",
body: req.body
});
response.body.pipe(res);
} catch (e) {
res.status(500).send("error");
}
});
The above code functions correctly, but I'm unsure if it saves the req.body
data into memory before sending it to the backend API. I want to validate this and understand how to effectively ensure it doesn't.