A wrapper for js-yaml parser
You can install this module using NPM:
npm install --save node-yaml
Read and parse YAML file.
- file Path to file or file descriptor
- null|string|object Options:
- [string] encoding (default = utf8)
- [object] schema - specifies a schema to use. More information about this option here (default - defaultSafe).
- defaultSafe - all supported YAML types, without unsafe ones
- defaultFull - all supported YAML types
- failsafe - only strings, arrays and plain objects
- json - all JSON-supported types
- core - same as json schema
yaml = require "node-yaml"
yaml.read "path/to/file.yaml",
encoding: "utf8"
schema: yaml.schema.defaultSafe, (err, data) ->
throw err if err
console.log data
Note: You also can use path without file extension (only for yaml.read and yaml.readSync).
Note: yaml.schema.defaultSafe schema used by default because is that recomended loading way.
Synchronous version of yaml.read. Return the contents of the file
Parse and write YAML to file.
- int|string file - Path to file or file descriptor
- object data - Some data to write
- null|string|object options:
- [string] encoding (default = utf8)
- [object] schema - specifies a schema to use. More information about this option here (default - defaultSafe).
- defaultSafe - all supported YAML types, without unsafe ones
- defaultFull - all supported YAML types
- failsafe - only strings, arrays and plain objects
- json - all JSON-supported types
- core - same as json schema
{write} = require "node-yaml"
data =
foo: "foo"
bar: "bar"
write "path/to/file.yaml", data, "utf8", (err) -> throw err if err
Synchronous version of yaml.write.
Parse YAML.
- string - YAML string to parse
- [object] options:
- [object] schema
{parse} = require "node-yaml"
data = """
foo: foo
bar: bar
"""
console.log parse data
Convert JSON into YAML.
{dump} = require "node-yaml"
data =
foo: "foo"
bar: "bar"
console.log dump data