{"library":"node-yaml","title":"Node.js YAML File Wrapper","description":"node-yaml is a streamlined wrapper library for the popular js-yaml parser, simplifying file-based YAML operations in Node.js environments. It provides convenient asynchronous and synchronous methods like `read`, `write`, `readSync`, and `writeSync` for handling YAML files. The current stable version is 4.0.1. Released with native ESM support in v4.0.0, it shifted js-yaml to a peer dependency, requiring manual installation of js-yaml. It aims for a stable, active release cadence, indicated by recent minor updates following a major rewrite. Its key differentiator is abstracting away the boilerplate of file system operations when working with YAML data, making it easier to parse and serialize YAML to and from files compared to directly using js-yaml's `safeLoad` and `safeDump` functions with `fs` module operations.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-yaml"],"cli":null},"imports":["import { read } from 'node-yaml'","import { readSync } from 'node-yaml'","import { write } from 'node-yaml'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { read, write } from 'node-yaml';\nimport { rm, mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nconst testDir = join(process.cwd(), 'temp_yaml_test');\nconst filePath = join(testDir, 'config.yaml');\n\nasync function runExample() {\n  await rm(testDir, { recursive: true, force: true });\n  await mkdir(testDir, { recursive: true });\n\n  const config = {\n    database: {\n      host: 'localhost',\n      port: 5432,\n      user: 'admin'\n    },\n    settings: {\n      debug: true,\n      logLevel: 'info'\n    }\n  };\n\n  try {\n    // Write the YAML content to a file\n    await write(filePath, config);\n    console.log(`YAML content written to ${filePath}`);\n\n    // Read the YAML content back from the file\n    const readConfig = await read(filePath);\n    console.log('\\nFile content:\\n%s', JSON.stringify(readConfig, null, 2));\n\n    // Demonstrate omitting file extension (if 'config.yaml' exists)\n    const readConfigNoExt = await read(join(testDir, 'config'));\n    console.log('\\nFile content (no extension):\\n%s', JSON.stringify(readConfigNoExt, null, 2));\n\n  } catch (err) {\n    console.error('Error during YAML operations:\\n%s', String(err));\n  } finally {\n    await rm(testDir, { recursive: true, force: true });\n    console.log(`Cleaned up ${testDir}`);\n  }\n}\n\nrunExample();\n","lang":"typescript","description":"This example demonstrates how to write a JavaScript object to a YAML file and then read it back using both explicit and implicit file extensions, utilizing `node-yaml`'s asynchronous API.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}