Registry / devops / chmodrp

chmodrp

JSON →
library1.0.2jsnpmunverified

`chmodrp` is a lightweight utility package for Node.js that provides a recursive `chmod` functionality, mirroring the behavior of the `chmod -R` command-line operation. It exposes this capability through a modern, Promise-based API, simplifying asynchronous file permission management. The current stable version is 1.0.2, and as a focused utility, it typically follows an infrequent release cadence, with updates primarily for maintenance or minor enhancements. Its core differentiator is the ergonomic Promise interface, which integrates seamlessly with `async/await` patterns, offering a significant improvement over traditional callback-based `fs` methods for ensuring consistent file and directory permissions in build systems, deployment scripts, and automated administrative tasks.

npm install chmodrp
INSTALL
IMPORT
SIG · CHMODRP
C
chmodrp
devopsjavascriptv1.0.2
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.

chmodrp
import chmodrp from 'chmodrp';
const chmodrp = require('chmodrp');
The package is ESM-only since its initial release, requiring `import` syntax. CommonJS `require()` will not work directly.

This example demonstrates how to use `chmodrp` to recursively set file and directory permissions within a temporary directory, showing basic setup and error handling.

import chmodrp from 'chmodrp'; import { mkdtemp, writeFile, mkdir } from 'node:fs/promises'; import { join } from 'node:path'; import { tmpdir } from 'node:os'; async function setupAndChangePermissions() { const baseTempDir = join(tmpdir(), 'chmodrp-example-'); const tempDir = await mkdtemp(baseTempDir); const filePath1 = join(tempDir, 'file1.txt'); const subDirPath = join(tempDir, 'sub-dir'); const filePath2 = join(subDirPath, 'file2.txt'); console.log(`Created temporary base directory: ${tempDir}`); // Create files and directories await writeFile(filePath1, 'Content for file 1.'); await mkdir(subDirPath, { recursive: true }); await writeFile(filePath2, 'Content for file 2.'); console.log('Initial files and directories created.'); console.log('Changing permissions recursively to 0o755 (rwxr-xr-x)...'); try { // Recursively change permissions for all files and directories within tempDir await chmodrp(tempDir, 0o755); console.log('Permissions changed successfully for:', tempDir); } catch (error) { console.error('Failed to change permissions:', error); process.exit(1); } // In a real application, you might verify permissions here or proceed with cleanup. // For cleanup, use 'rm -rf' or Node.js fs.rm (recursive: true) for Node 14+ // await rm(tempDir, { recursive: true, force: true }); // Node 14.14+ // console.log('Cleaned up temporary directory.'); } setupAndChangePermissions().catch(console.error);
Debug
Known issues
gotchaThe `mode` argument expects an octal number (e.g., `0o755`) or an integer representing the permission. Passing a string like '755' will lead to incorrect permissions or a `TypeError`.
fix
Always use octal literal notation (e.g., `0o755`) or parse strings to integers (`parseInt('755', 8)`) for the permission `mode`.
affects: >=1.0.0
Errors
Common errors & fixes
EACCES: permission denied, chmod
The Node.js process does not have sufficient operating system permissions to change permissions on the specified path or its contents.
fix
Ensure the user running the Node.js process has appropriate write and execute permissions on the target directory and its files. This may involve using `sudo` or adjusting file ownership/permissions manually beforehand.
TypeError: The "mode" argument must be of type number. Received type string ('755')
The permission mode was provided as a string instead of a numerical value (octal or integer).
fix
Correct the mode argument to an octal number, e.g., change `'755'` to `0o755`.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
chmodrp — npm install chmodrp · libregistry