Recently, we had to upgrade our Node version to 18.4 because of reasons. And one of the new features of Node 18 is that the http server now has a default 5 minute timeout for requests which breaks certain slow endpoints in our app. We need to increase that.
Our project is in TypeScript and having code like:
import * as express from 'express'; import * as http from 'http'; this.app = express(); //numerous configurations const server = http.createServer(this.app);
Now here would be the part where we increase this timeout. However, none of the following work
server.requestTimeout = 9000000; // some large number
TSError: ⨯ Unable to compile TypeScript:
server/init.ts:232:12 – error TS2339: Property ‘requestTimeout’ does not exist on type ‘Server’.
server.setTimeout(9000000); //does not actually increase the request timeout
However, if launch a debugger and manually input
server.requestTimeout = 9000000 in the console, that seems to work perfectly.
So how do I go about changing this property?
Update the corresponding
@type/ package. If the package is up to date, it’s maybe not yet patched. You can create a
.d.ts to augment the type declaration with the missing property. That should do the trick until they patch it.
Answered By – Clem
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0