Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/fs.ts>chmod

A JavaScript extension package for building strong and modern applications.
Latest
function chmod
import { chmod } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";

Changes the permission of the specified file or directory.

The mode is a sequence of 3 octal numbers. The first/left-most number specifies the permissions for the owner. The second number specifies the permissions for the group. The last/right-most number specifies the permissions for others. For example, with a mode of 0o764, the owner (7) can read/write/execute, the group (6) can read/write and everyone else (4) can read only.

Number Description
7 read, write, and execute
6 read and write
5 read and execute
4 read only
3 write and execute
2 write only
1 execute only
0 no permission

NOTE: This function is only available in Node.js, Deno and Bun, and only works in Unix/Linux systems, in other environments, it's a no-op.

Examples

Example 1

import { chmod } from "@ayonli/jsext/fs";

// Change the file's permission to read/write for owner, read for group and others.
await chmod("/path/to/file.txt", 0o644);

Parameters

path: string
mode: number

Returns

Promise<void>