{"id":15743,"library":"openshift-rest-client","title":"OpenShift REST Client for Node.js","description":"openshift-rest-client is a Node.js library designed to interact with the OpenShift REST API. It provides a client that translates OpenShift API Path Item Objects (like `/apis/project.openshift.io/v1/projects`) into idiomatic JavaScript object chains, allowing developers to interact with resources using methods such as `.get()`, `.post()`, `.delete()`, `.patch()`, and `.put()`. The library is currently stable at version 10.0.0 and follows a release cadence tied to Node.js LTS versions, introducing breaking changes primarily for dropping support for End-of-Life Node.js runtimes. A key differentiator is its integration with the kubernetes-client module for configuration, enabling flexible authentication and cluster context management, similar to the Fabric8 Maven Plugin but tailored for Node.js environments. It simplifies API interaction by providing aliases for common API groups and supports query parameters and path templating, making it a robust tool for programmatic OpenShift management from Node.js applications.","status":"active","version":"10.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/nodeshift/openshift-rest-client","tags":["javascript","Openshift","Node.js"],"install":[{"cmd":"npm install openshift-rest-client","lang":"bash","label":"npm"},{"cmd":"yarn add openshift-rest-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add openshift-rest-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used by default to load OpenShift/Kubernetes cluster configuration (e.g., from `~/.kube/config`).","package":"kubernetes-client","optional":false}],"imports":[{"note":"The primary client factory. While the README shows CommonJS `require('pkg').OpenshiftClient`, modern Node.js environments (v10+) support named ESM imports for CJS modules. Avoid `require('pkg')` if you intend to get the factory directly.","wrong":"const OpenshiftClient = require('openshift-rest-client');","symbol":"OpenshiftClient","correct":"import { OpenshiftClient } from 'openshift-rest-client';"},{"note":"A utility export for advanced configuration options, leveraging `kubernetes-client`'s config module. Direct named import is preferred in ESM.","wrong":"const configModule = require('openshift-rest-client'); const specificConfig = configModule.config;","symbol":"config","correct":"import { config } from 'openshift-rest-client';"},{"note":"Type definition for the instantiated OpenShift client object, useful for TypeScript projects.","symbol":"OpenShiftClient","correct":"import type { OpenShiftClient } from 'openshift-rest-client';"}],"quickstart":{"code":"import { OpenshiftClient } from 'openshift-rest-client';\nimport type { OpenShiftClient } from 'openshift-rest-client';\n\n// Configure the client using environment variables for safety, or a specific kubeconfig path.\n// process.env.KUBECONFIG can point to a specific file, or OpenshiftClient() will try default paths.\nconst kubeConfigPath = process.env.KUBECONFIG || undefined;\n\nasync function runClientExample() {\n  let client: OpenShiftClient;\n  try {\n    if (kubeConfigPath) {\n      console.log(`Attempting to connect using kubeconfig: ${kubeConfigPath}`);\n      client = await OpenshiftClient({ config: kubeConfigPath });\n    } else {\n      console.log('Attempting to connect using default kubeconfig or in-cluster configuration.');\n      client = await OpenshiftClient();\n    }\n\n    console.log('Successfully connected to OpenShift API.');\n\n    // Fetch all projects accessible by the authenticated user\n    console.log('Fetching all projects...');\n    const projectList = await client.apis['project.openshift.io'].v1.projects.get();\n    console.log(`Found ${projectList.body.items.length} projects.`);\n\n    // Log details of the first project found, if any\n    if (projectList.body.items.length > 0) {\n      const firstProjectName = projectList.body.items[0].metadata?.name;\n      console.log(`First project name: ${firstProjectName}`);\n    }\n\n    // Example: List all build configs in the 'default' namespace\n    console.log('Fetching build configs in default namespace...');\n    const buildConfigs = await client.apis['build.openshift.io'].v1.namespaces('default').buildconfigs.get();\n    console.log(`Found ${buildConfigs.body.items.length} build configs in 'default' namespace.`);\n\n  } catch (error: any) {\n    console.error('An error occurred:', error.message);\n    if (error.response?.body) {\n      console.error('API Error Response:', JSON.stringify(error.response.body, null, 2));\n    }\n  }\n}\n\nrunClientExample();","lang":"typescript","description":"This example demonstrates how to initialize the OpenShift client, connect to an API endpoint (projects), and fetch resources. It includes basic error handling and uses environment variables for flexible configuration."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 20 or higher. Refer to the package's `engines` field for exact supported versions.","message":"Version 10.0.0 removed support for Node.js 18. Ensure your environment uses Node.js 20, 22, or 24.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Upgrade your Node.js runtime to version 18 or higher.","message":"Version 9.0.0 removed support for Node.js 16. Projects must be on Node.js 18 or newer.","severity":"breaking","affected_versions":">=9.0.0 <10.0.0"},{"fix":"Upgrade your Node.js runtime to version 16 or higher.","message":"Version 8.0.0 removed support for Node.js 14. Projects must be on Node.js 16 or newer.","severity":"breaking","affected_versions":">=8.0.0 <9.0.0"},{"fix":"Review any custom HTTP client configurations or options previously passed to `request`. Adapt them to `undici`'s API or the `kubernetes-client`'s options for underlying HTTP client configuration.","message":"Version 7.1.0 replaced the underlying `request` library with `undici` for HTTP operations. This may affect custom HTTP agents, proxy configurations, or specific `request` options no longer supported or handled differently by `undici`.","severity":"breaking","affected_versions":">=7.1.0"},{"fix":"Replace `strictSSL: false` with `rejectUnauthorized: false` in your client configuration when dealing with self-signed certificates or untrusted CAs.","message":"The `strictSSL` option was deprecated and replaced with `rejectUnauthorized` in v8.0.3. Using `strictSSL` might lead to unexpected behavior or be ignored.","severity":"gotcha","affected_versions":">=8.0.3"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Double-check the OpenShift API documentation for the exact path and method. Ensure the API version (e.g., `v1`) and resource names (e.g., `projects`) are correct and in the correct order.","cause":"Incorrect API path traversal or a typo in the API group, version, or resource name. The client builds the API structure dynamically based on the OpenShift API schema.","error":"TypeError: client.apis['project.openshift.io'].v1.projects.get is not a function"},{"fix":"Verify your OpenShift cluster URL and network connectivity. If using self-signed certificates, ensure `rejectUnauthorized: false` is set in your client configuration. Also check for proxy issues.","cause":"This often indicates a network connection issue, an incorrect cluster URL, or a problem with TLS/SSL verification (e.g., self-signed certificate without `rejectUnauthorized: false`).","error":"Error: read ECONNRESET"},{"fix":"Upgrade your Node.js runtime to one of the supported versions (20, 22, or 24) using a Node.js version manager like `nvm` or `volta`.","cause":"The application is running on an unsupported Node.js version, as indicated by the package's `engines` field and recent breaking changes.","error":"Error: The client only supports Node.js versions 20, 22, 24"}],"ecosystem":"npm"}