fs.F_OK, fs.R_OK, fs.W_OK, and fs.X_OK from the root fs module to fs.constants, addressing the deprecation of these constants at the module root level.
What It Does
The codemod transforms:fs.F_OK→fs.constants.F_OKfs.R_OK→fs.constants.R_OKfs.W_OK→fs.constants.W_OKfs.X_OK→fs.constants.X_OK
Usage
Examples
Basic Usage
Before
After
Combined Access Modes
Before
After
Multiple Checks
Before
After
Access Mode Constants
F_OK - File Existence
Checks if the file exists (without checking permissions):R_OK - Read Permission
Checks if the file is readable:W_OK - Write Permission
Checks if the file is writable:X_OK - Execute Permission
Checks if the file is executable:Why Migrate?
Moving tofs.constants:
- Groups related constants together
- Aligns with the location of other fs constants
- Provides better API organization
- Matches conventions used by other Node.js modules
Combining Access Modes
You can combine multiple access modes using the bitwise OR operator (|):
Common Patterns
Check Before Read
Verify Multiple Files
Other fs.constants
Thefs.constants object also includes:
- File Open Flags:
O_RDONLY,O_WRONLY,O_RDWR, etc. - File Copy Flags:
COPYFILE_EXCL,COPYFILE_FICLONE, etc. - File Type Constants:
S_IFMT,S_IFREG,S_IFDIR, etc.