Regardless of the mode used, pkg exposes all files included in the package under a /snapshot/ prefix. This is handled by a Virtual Filesystem (VFS) layer that intercepts standard Node.js fs calls.
To read a file that was included in your package, use the absolute path starting with /snapshot/.
Example:
If your project has a file at app/config.json, you access it in your code as:
fs.readFileSync('/snapshot/app/config.json').
Note on Native Addons:
Native addons (.node files) cannot be loaded directly from memory. Both modes will automatically extract these files to ~/.cache/pkg/<sha256>/ on their first load and then execute them using the real process.dlopen.
// Accessing a packaged file at runtime
const fs = require('fs');
const config = fs.readFileSync('/snapshot/app/config.json');