Skip to content

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>;
path

string

Resource<string>
// Read a configuration file
const configResource = createFileResource('./config.json');
// Access the file content
if (!configResource.loading && !configResource.error) {
const configText = configResource.data; // string content of the file
const config = JSON.parse(configText);
}