{"library":"server-ready","title":"Server Port Readiness Checker","description":"server-ready is a lightweight Node.js utility designed to ascertain when a network server is listening and ready to accept TCP connections on a specified port. The package operates by repeatedly attempting to establish a TCP connection to the target port, polling every 250 milliseconds until a connection is successful or a default timeout of 20 seconds is reached. While functional, it is important to note that the package, currently at version 0.3.1, has not received updates since 2017, suggesting it is unmaintained. It is primarily intended for use in Node.js scripts, deployment processes, or testing environments where programmatic waiting for server startup is required. Its key differentiator is its simplicity and singular focus on port availability, without deeper application-level health checks.","language":"javascript","status":"abandoned","last_verified":"Tue Apr 21","install":{"commands":["npm install server-ready"],"cli":null},"imports":["const serverReady = require('server-ready')","const serverReady = require('server-ready'); serverReady.timeout = 5000;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const serverReady = require('server-ready');\nconst http = require('http');\n\nconst port = 3001;\n\n// Simulate a server that takes a moment to start\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('Server is ready!\\n');\n});\n\n// Start the server after a short delay\nsetTimeout(() => {\n  server.listen(port, () => {\n    console.log(`Simulated server started on port ${port}`);\n  });\n}, 1000);\n\n// Use server-ready to detect when the port is open\nconsole.log(`Waiting for server to be ready on port ${port}...`);\nserverReady(port, (err) => {\n  if (err) {\n    console.error(`Error: ${err.message}`);\n  } else {\n    console.log(`Port ${port} is open or has just opened.`);\n    // Make a request to the ready server\n    http.get(`http://localhost:${port}`, (res) => {\n      let data = '';\n      res.on('data', (chunk) => data += chunk);\n      res.on('end', () => {\n        console.log(`Received from server: ${data.trim()}`);\n        server.close(() => console.log('Server closed.'));\n      });\n    }).on('error', (e) => {\n      console.error(`HTTP request error: ${e.message}`);\n      server.close(() => console.log('Server closed due to HTTP error.'));\n    });\n  }\n});\n\n// Optional: Set a custom timeout for server-ready\n// serverReady.timeout = 5000; // 5 seconds","lang":"javascript","description":"This quickstart demonstrates how to use `server-ready` to wait for a simulated HTTP server to become available on a specific port, then makes a request to confirm.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}