createFileResource
Create a resource that reads a file from the file system.
This is a convenience function that creates a resource for reading file content using the AlloyHost file system API. The file is read as text when the resource is created.
import { createFileResource } from "@alloy-js/core";
function createFileResource(path: string): Resource<string>;
Parameters
Section titled “Parameters”path |
|
Returns
Section titled “Returns”Resource<string>
Example
Section titled “Example”// Read a configuration fileconst configResource = createFileResource('./config.json');
// Access the file contentif (!configResource.loading && !configResource.error) { const configText = configResource.data; // string content of the file const config = JSON.parse(configText);}