Node.js-specific extensions for yoga-om, providing convenient wrappers for file system operations, environment variables, and more.
spago install yoga-om-core yoga-om-node- File operations:
readFile,writeFile,readTextFile,writeTextFile,appendFile, etc. - File system:
exists,mkdir,rmdir,unlink - Environment variables:
getEnv,lookupEnv,setEnv - Process:
cwdfor current working directory
All operations are wrapped in Om with proper error types.
import Yoga.Om.Node as Node
loadConfig :: Om {} (envNotFound :: { variable :: String }) Config
loadConfig = do
apiKey <- Node.getEnv "API_KEY"
dbUrl <- Node.getEnv "DATABASE_URL"
pure { apiKey, dbUrl }import Yoga.Om.Node as Node
processFile :: Om {} (fileReadError :: _, fileWriteError :: _) Unit
processFile = do
content <- Node.readTextFile "input.txt"
let processed = String.toUpper content
Node.writeTextFile "output.txt" processedimport Yoga.Om.Node as Node
safeRead :: FilePath -> Om {} _ (Maybe String)
safeRead path = do
fileExists <- Node.exists path
if fileExists
then Just <$> Node.readTextFile path
else pure NothingThe package defines error type aliases for common failures:
FileError- IncludesfileNotFound,fileReadError,fileWriteError,fileSystemErrorEnvError- IncludesenvNotFound
These can be extended with your own error types:
type MyErrors r = Node.FileError + Node.EnvError +
( customError :: String | r )Tests are colocated with the implementation in the test/ directory:
# Run tests
cd packages/yoga-om-node && spago test
# Or from workspace root
bun test:nodeSee test/Test/Node.purs for test examples.
yoga-om-node/
├── src/
│ └── Yoga/
│ └── Om/
│ └── Node.purs # Node.js extensions
└── test/ # Tests colocated here!
└── Test/
├── Main.purs # Test runner
└── Node.purs # Node-specific tests
- yoga-om-core - Core Om functionality (required)
- yoga-om-rom - Reactive Om: Bolson FRP integration
- yoga-om-strom - Stream Om: Pull-based streaming
For more examples, see the tests and main README.