Categories
JavaScript Answers

How to modify the Node.js request default timeout time?

Spread the love

To modify the Node.js request default timeout time, we set the timeout property.

For instance, we write

const http = require("http");
const server = http
  .createServer((req, res) => {
    setTimeout(() => {
      res.writeHead(200, { "Content-Type": "text/plain" });
      res.end("Hello World\n");
    }, 200);
  })
  .listen(1337, "127.0.0.1");

server.timeout = 20;
console.log("Server running at http://127.0.0.1:1337/");

to create a web server with createServer.

And we set the request timeout by setting the server.timeout property to a time milliseconds.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *