Registry / devops / libnpmorg

libnpmorg

JSON →
library8.0.1jsnpmunverified

libnpmorg is a Node.js library that provides a programmatic interface for interacting with the npm Org membership API. It allows developers to manage organization members, roles, and rosters directly from their applications, mirroring the functionality of `npm org` commands. The current stable version is 8.0.1, though the package is part of the larger npm CLI monorepo and receives updates frequently, often alongside npm CLI releases, as seen by recent activity up to `v11.12.1` of the CLI. Key differentiators include its direct integration with `npm-registry-fetch` for consistent registry interaction and its focus on a specific, well-defined subset of npm's functionality related to organizations. It is primarily used within the npm CLI itself but is exposed for third-party tools needing fine-grained control over npm organization management.

npm install libnpmorg
INSTALL
IMPORT
SIG · LIBNPMORG
L
libnpmorg
devopsjavascriptv8.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

set
import { set } from 'libnpmorg'
const { set } = require('libnpmorg')
The README examples show `require`, but ESM `import` is the modern approach. `libnpmorg` exports named functions.
ls
import { ls } from 'libnpmorg'
import org from 'libnpmorg'; org.ls(...)
The library exports individual functions, not a default object. Destructuring is required.
ls.stream
import { ls } from 'libnpmorg'; const stream = ls.stream(...)
import { lsStream } from 'libnpmorg'
`stream` is a property of the `ls` function, not a top-level export.

This example demonstrates how to list, add, and remove members from an npm organization using `libnpmorg` functions, including handling authentication.

import { ls, set, rm } from 'libnpmorg'; const ORG_NAME = 'my-test-org'; // Replace with a real org name or test org const USER_NAME = 'testuser'; // Replace with a real username const AUTH_TOKEN = process.env.NPM_TOKEN ?? ''; // Ensure you have an npm automation token async function manageOrgMembership() { if (!AUTH_TOKEN) { console.error('NPM_TOKEN environment variable is not set. Cannot perform authenticated operations.'); return; } try { console.log(`Listing members of ${ORG_NAME}...`); const roster = await ls(ORG_NAME, { token: AUTH_TOKEN }); console.log('Current Roster:', roster); console.log(`Adding ${USER_NAME} to ${ORG_NAME} as developer...`); const newMembership = await set(ORG_NAME, USER_NAME, 'developer', { token: AUTH_TOKEN }); console.log('New Membership:', newMembership); console.log(`Roster after adding ${USER_NAME}:`); console.log(await ls(ORG_NAME, { token: AUTH_TOKEN })); console.log(`Removing ${USER_NAME} from ${ORG_NAME}...`); await rm(ORG_NAME, USER_NAME, { token: AUTH_TOKEN }); console.log(`${USER_NAME} removed.`); console.log(`Roster after removing ${USER_NAME}:`); console.log(await ls(ORG_NAME, { token: AUTH_TOKEN })); } catch (error) { console.error('An error occurred:', error.message); if (error.code === 'EOTP') { console.error('This operation requires an OTP token. Please retry with `{otp: <your-2fa-token>}`.'); } } } manageOrgMembership();
Debug
Known issues
breakinglibnpmorg has a strong dependency on recent Node.js versions. As of `v8.0.1`, it requires Node.js `^20.17.0 || >=22.9.0`. Older Node.js versions will not be supported.
fix
Upgrade your Node.js environment to a compatible version (e.g., Node.js 20.17.0 or newer).
affects: >=8.0.0
gotchaAuthentication is mandatory for most `libnpmorg` operations. A `token` option must be provided, or npm's configured credentials must be available through `npm-registry-fetch`'s default behavior.
fix
Pass `{ token: 'your_auth_token' }` in the `opts` object for each call, or ensure npm is configured with a valid token for the registry.
affects: >=1.0.0
gotchaTwo-factor authentication (2FA) operations, such as changing roles or removing members, might require an OTP token. The library will throw an `EOTP` error if one is needed.
fix
Catch errors and if `err.code === 'EOTP'`, retry the request with `{ otp: 'your_2fa_code' }` included in the options.
affects: >=1.0.0
Errors
Common errors & fixes
Error: ENEEDAUTH npm-registry-fetch No auth for the current registry and scope.
Attempting to perform an authenticated operation without providing a valid authentication token or without being logged in via npm CLI.
fix
Ensure `opts.token` is provided with a valid npm automation token, or run `npm login` in your environment.
Error: EOTP This command requires a one-time password.
An operation (e.g., `set` or `rm`) was attempted on an organization or user that requires 2FA, but no OTP was supplied.
fix
Retry the operation, including `{ otp: 'your_6_digit_otp' }` in the options object.
TypeError: org.set is not a function
Attempting to call `org.set` (or `org.ls`, `org.rm`) after importing `libnpmorg` as a default import instead of using named imports/destructuring.
fix
Change `import org from 'libnpmorg'` to `import { set, ls, rm } from 'libnpmorg'`.
Upgrade
Version history
8.0.1latest on npm
Audit
Dependencies
npm-registry-fetchrequiredUsed internally for all network requests to the npm registry.
Agent activity
2 hits · last 30 days
node
2
Resources
libnpmorg — npm install libnpmorg · libregistry