{"id":17705,"library":"httpolyglot","title":"HTTPolyglot (Abandoned - Use @httptoolkit/httpolyglot)","description":"The original `httpolyglot` package, last published in 2016, is a Node.js module designed to serve both HTTP and HTTPS connections over a single port by sniffing the initial bytes of an incoming connection to determine the protocol. This package, version `0.1.2`, is **abandoned** and no longer maintained. Its functionality is limited to HTTP/1.x and HTTPS with outdated Node.js compatibility (down to `v0.10.0`). For modern applications, including HTTP/2 support, improved TLS handling, TypeScript compatibility, and active maintenance, developers are strongly advised to use the actively maintained and significantly enhanced fork, `@httptoolkit/httpolyglot`, which serves as the de facto successor for this functionality. The original package has no defined release cadence and lacks contemporary features and security updates.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/mscdex/httpolyglot","tags":["javascript","http","https","multiplex","polyglot"],"install":[{"cmd":"npm install httpolyglot","lang":"bash","label":"npm"},{"cmd":"yarn add httpolyglot","lang":"bash","label":"yarn"},{"cmd":"pnpm add httpolyglot","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The original `httpolyglot` package uses CommonJS `require`. The recommended, actively maintained fork, `@httptoolkit/httpolyglot`, is an ESM-first module and should be imported using `import` syntax.","wrong":"const httpolyglot = require('httpolyglot'); httpolyglot.createServer(...);","symbol":"createServer","correct":"import { createServer } from '@httptoolkit/httpolyglot';"},{"note":"While `Server` is exported, `createServer` is the more common entry point. The fork supports `tls.Server` instances in its config, unlike the original.","symbol":"Server","correct":"import { Server } from '@httptoolkit/httpolyglot';"},{"note":"The `@httptoolkit/httpolyglot` package exports named symbols. Importing the entire module namespace is done with `import * as name`.","wrong":"import httpolyglot from '@httptoolkit/httpolyglot';","symbol":"default","correct":"import * as httpolyglot from '@httptoolkit/httpolyglot';"}],"quickstart":{"code":"import * as httpolyglot from '@httptoolkit/httpolyglot';\nimport * as fs from 'node:fs';\nimport * as https from 'node:https'; // For generating certificates\n\n// --- Utility to generate self-signed certs for testing ---\n// In a real app, use proper certificate management (e.g., LetsEncrypt)\nconst generateSelfSignedCert = () => {\n  try {\n    fs.readFileSync('server.key');\n    fs.readFileSync('server.crt');\n  } catch (e) {\n    console.log('Generating self-signed certificates...');\n    const { generateKeyPairSync } = require('node:crypto');\n    const { privateKey, publicKey } = generateKeyPairSync('rsa', {\n      modulusLength: 2048,\n      publicKeyEncoding: { type: 'spki', format: 'pem' },\n      privateKeyEncoding: { type: 'pkcs8', format: 'pem' },\n    });\n    fs.writeFileSync('server.key', privateKey);\n    // A simple self-signed cert (for testing only!)\n    const cert = `-----BEGIN CERTIFICATE-----\\nMIIDDDCCAfSgAwIBAgIUQd+Wj+T/h7g8v4f5g4f/g4f/g4f/g4f/g4f/g4f/g4f\\nMBMGCSqGSIb3DQEBCwUAMBQxDDAKBgNVBAMMA2xvYzAeFw0yNjA0MjMyMDIyNDZa\\nFw0yNzA0MjMyMDIyNDZaMBQxDDAKBgNVBAMMA2xvYWMwggEiMA0GCSqGSIb3DQEB\\nAQUAA4IBDwAwggEKAoIBAQCmF5fN+h/d+g/g4f/g4f/g4f/g4f/g4f/g4f/g4f\\nAgMBAAGjMDAuMBsGA1UdEQQUMBKCDmRpcmVjdC5leGFtcGxlMA4GA1UdDwEB/wQE\\nAwIBAzANBgkqhkiG9w0BAQsFAAOCAQEAy/g4f/g4f/g4f/g4f/g4f/g4f/g4f\\n-----END CERTIFICATE-----\\n`; // Placeholder\n    fs.writeFileSync('server.crt', cert);\n    console.log('Certificates generated. PLEASE DO NOT USE IN PRODUCTION.');\n  }\n};\ngenerateSelfSignedCert();\n// --- End cert generation utility ---\n\nconst key = fs.readFileSync('server.key');\nconst cert = fs.readFileSync('server.crt');\n\nhttpolyglot.createServer({\n  // For the @httptoolkit fork, TLS config is nested under `tls`\n  tls: {\n    key: key,\n    cert: cert,\n  },\n}, function(req, res) {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end((req.socket.encrypted ? 'HTTPS' : 'HTTP') + ' Connection!\\nHello from @httptoolkit/httpolyglot!');\n}).listen(9000, 'localhost', function() {\n  console.log('httpolyglot server listening on port 9000');\n  console.log('Visit http://localhost:9000 and https://localhost:9000 in your browser.');\n  console.log('Ensure you accept any self-signed certificate warnings for HTTPS.');\n});\n","lang":"typescript","description":"This quickstart demonstrates how to set up an `@httptoolkit/httpolyglot` server that listens for both HTTP and HTTPS connections on the same port, responding differently based on the protocol. It includes a basic self-signed certificate generation utility for local testing purposes (not for production)."},"warnings":[{"fix":"Migrate to the actively maintained `@httptoolkit/httpolyglot` package: `npm install @httptoolkit/httpolyglot`.","message":"The original `httpolyglot` package (v0.1.2) is abandoned and has not been updated in over 9 years. It lacks support for modern Node.js versions, HTTP/2, and contains unaddressed issues. It is strongly recommended NOT to use this package in any new or existing project.","severity":"breaking","affected_versions":"<=0.1.2"},{"fix":"Update your `createServer` call to use the nested `tls` object: `httpolyglot.createServer({ tls: { key: ..., cert: ... } }, ...)`.","message":"The API for `createServer` in the actively maintained fork (`@httptoolkit/httpolyglot`) has changed significantly. TLS configuration is now nested under a `tls` property within the main configuration object. The original package accepted `key` and `cert` directly at the top level.","severity":"breaking","affected_versions":"all versions of `@httptoolkit/httpolyglot` when migrating from `httpolyglot`"},{"fix":"Ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`) and use `import * as httpolyglot from '@httptoolkit/httpolyglot';` or specific named imports.","message":"The `@httptoolkit/httpolyglot` package is written in TypeScript and primarily designed for ESM usage. Attempting to `require()` it in a CommonJS context or using incorrect import syntax can lead to runtime errors or undefined modules.","severity":"gotcha","affected_versions":"all versions of `@httptoolkit/httpolyglot`"},{"fix":"Update your Node.js environment to version 20 or newer to use `@httptoolkit/httpolyglot`.","message":"The `@httptoolkit/httpolyglot` fork drops support for very old Node.js versions, requiring Node.js v20 or newer. The original `httpolyglot` package specified `>=0.10.0`.","severity":"breaking","affected_versions":"all versions of `@httptoolkit/httpolyglot`"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure you are using the correct, actively maintained `@httptoolkit/httpolyglot` package. If already installed, verify it's imported correctly via ESM: `import * as httpolyglot from '@httptoolkit/httpolyglot';`.","cause":"Attempting to use the `createServer` method from the original, abandoned `httpolyglot` package with an outdated Node.js environment or when the package failed to load correctly due to CJS/ESM incompatibility.","error":"httpolyglot.createServer is not a function"},{"fix":"Adjust your `createServer` call to `httpolyglot.createServer({ tls: { key: fs.readFileSync('server.key'), cert: fs.readFileSync('server.crt') } }, ...);`.","cause":"Using the old configuration format (direct `key`, `cert` options) with the new `@httptoolkit/httpolyglot` API, which expects these under a nested `tls` property.","error":"TypeError: Cannot read properties of undefined (reading 'key')"},{"fix":"Convert your project or the relevant file to use ES Modules by adding `\"type\": \"module\"` to your `package.json` or by using `.mjs` file extensions. Then use `import * as httpolyglot from '@httptoolkit/httpolyglot';`. Alternatively, use dynamic `import()` for specific needs.","cause":"Attempting to `require()` the `@httptoolkit/httpolyglot` package in a CommonJS environment, but the package is ESM-only.","error":"ERR_REQUIRE_ESM: require() of ES Module .../node_modules/@httptoolkit/httpolyglot/dist/index.js from ... not supported."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}