A wrapper for js-yaml parser
You can install this module using NPM:
npm install --save node-yamlRead 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) ->
if err
throw err
console.log dataNote: 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.
This method return an instance of Promise.
DEPRECATED: Use yaml.read without callback instead
{readPromise} = require 'node-yaml'
readPromise 'path/to/file.yaml'
.then (data) -> console.log dataSynchronous 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 errThis method return an instance of Promise.
DEPRECATED: Use yaml.write without callback instead
{writePromise} = require 'node-yaml'
data =
foo: "foo"
bar: "bar"
writePromise 'path/to/file.yaml', data
.then ->
# Do something.
.catch (err) ->
# I just don't know what went wrong.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 dataConvert JSON into YAML.
{dump} = require 'node-yaml'
data =
foo: "foo"
bar: "bar"
console.log dump data