Package

purescript-yoga-om-node

Repository
rowtype-yoga/purescript-yoga-om-node
License
MIT-0
Uploaded by
pacchettibotti
Published on
2026-02-05T15:43:57Z

Node.js-specific extensions for yoga-om, providing convenient wrappers for file system operations, environment variables, and more.

Installation

spago install yoga-om-core yoga-om-node

What's Included

  • File operations: readFile, writeFile, readTextFile, writeTextFile, appendFile, etc.
  • File system: exists, mkdir, rmdir, unlink
  • Environment variables: getEnv, lookupEnv, setEnv
  • Process: cwd for current working directory

All operations are wrapped in Om with proper error types.

Usage

Reading Environment Variables

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 }

File Operations

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" processed

Checking File Existence

import 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 Nothing

Error Types

The package defines error type aliases for common failures:

  • FileError - Includes fileNotFound, fileReadError, fileWriteError, fileSystemError
  • EnvError - Includes envNotFound

These can be extended with your own error types:

type MyErrors r = Node.FileError + Node.EnvError + 
  ( customError :: String | r )

Testing

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:node

See test/Test/Node.purs for test examples.

Package Structure

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

See Also

For more examples, see the tests and main README.

Modules
Test.Main.Node
Yoga.Om.Node
Yoga.Om.Node.Test
Dependencies