Node.js wrapper for yq, a lightweight and portable command-line YAML processor.
npm install node-yqDuring installation, the corresponding yq binary file will be automatically downloaded to the project's bin directory.
- macOS (darwin) - x64, arm64
- Linux - x64, arm64
- Windows - x64
const yq = require('node-yq');
// Synchronous execution
const result = yq.execSync(['e', '.name', 'config.yaml']);
console.log(result);
// Asynchronous execution
yq.exec(['e', '.name', 'config.yaml'])
.then(result => {
console.log(result);
})
.catch(error => {
console.error(error);
});- Parameters:
args: yq command arguments arrayoptions: optional execution options, passed tochild_process.execSync
- Returns: command execution result string
- Parameters:
args: yq command arguments arrayoptions: optional execution options, passed tochild_process.spawn
- Returns: Promise, resolves to command execution result string
- Parameters:
filePath: YAML file pathoptions: optional execution options
- Returns: Promise, resolves to parsed YAML string
- Parameters:
filePath: YAML file pathoptions: optional execution options
- Returns: Promise, resolves to converted JSON string
- Parameters:
filePath: YAML file pathexpression: yq expression for extracting fieldsoptions: optional execution options
- Returns: Promise, resolves to extracted field value
- Parameters:
filePath: YAML file pathexpression: yq expression for specifying the field to updatevalue: new value to setoptions: optional execution options
- Returns: Promise, resolves to command execution result
- Returns: path to yq binary file
- Returns: boolean indicating if yq is installed
const yq = require('node-yq');
yq.parse('config.yaml')
.then(result => {
console.log(result);
})
.catch(error => {
console.error(error);
});const yq = require('node-yq');
yq.toJson('config.yaml')
.then(result => {
console.log(JSON.parse(result));
})
.catch(error => {
console.error(error);
});const yq = require('node-yq');
yq.extract('config.yaml', '.database.url')
.then(result => {
console.log(result);
})
.catch(error => {
console.error(error);
});const yq = require('node-yq');
yq.update('config.yaml', '.database.port', '3306')
.then(() => {
console.log('Successfully updated database port');
})
.catch(error => {
console.error(error);
});- This library automatically downloads yq binary files during installation, so network connection is required.
- The default supported yq version is 4.35.1.
- You can specify the yq version to install via the
YQ_VERSIONenvironment variable, for example:YQ_VERSION=4.35.0 npm install node-yq
- This library is a wrapper around the yq command-line tool, so usage is consistent with the yq command-line tool.
MIT