Work with the Virtual File System (VFS)
mainThe VirtualFS provides a Node.js-compatible in-memory filesystem. You can pre-populate it with files using vfs.writeFileSync() and then run files from that filesystem using container.runFile(path).
import { createContainer } from 'almostnode';
const container = createContainer();
const { vfs } = container;
// Pre-populate the virtual filesystem
vfs.writeFileSync('/src/index.js', `
const data = require('./data.json');
console.log('Users:', data.users.length);
module.exports = data;
`);
vfs.writeFileSync('/src/data.json', JSON.stringify({
users: [{ name: 'Alice' }, { name: 'Bob' }]
}));
// Run from the virtual filesystem
const result = container.runFile('/src/index.js');