Complete command-line interface documentation for @notfounnd/ini-parser - a professional INI file parser for Node.js.
- Introduction
- Installation
- Synopsis
- Arguments
- Options
- Advanced Example
- Exit Codes
- Error Messages and Solutions
- See Also
The @notfounnd/ini-parser CLI provides a command-line interface for parsing INI configuration files into JSON format. It offers a simple, fast way to convert INI files to structured JSON data directly from your terminal.
What it does:
- Parses INI files into JSON format
- Validates INI file syntax and structure
- Outputs results to stdout or saves to file
- Supports both simplified and metadata output formats
- Provides colored output for better readability
What it doesn't do:
- Convert JSON back to INI format
- Modify or edit INI files
- Merge multiple INI files
Install the CLI globally to use the ini-parser command from anywhere:
npm install -g @notfounnd/ini-parserAfter global installation, the ini-parser command will be available system-wide:
ini-parser --versionInstall as a project dependency and use via npm scripts or npx:
npm install @notfounnd/ini-parserThen use with npx:
npx ini-parser config.iniOr add to your package.json scripts:
{
"scripts": {
"parse-config": "ini-parser config.ini --output config.json"
}
}ini-parser <file> [options]General usage:
- Parse and output to stdout:
ini-parser <file> - Save to file:
ini-parser <file> --output <output-file> - Validate file:
ini-parser <file> --check - Show version:
ini-parser --version - Show help:
ini-parser --help
Required. Path to the INI file to parse.
Type: string
Description:
- Can be a relative or absolute path
- File must exist and be readable
- Supports any file extension (
.ini,.config,.properties, etc.)
Examples:
# Relative path
ini-parser config.ini
# Absolute path (Windows)
ini-parser C:\projects\app\config.ini
# Absolute path (Unix/Linux)
ini-parser /etc/app/config.ini
# Different file extensions
ini-parser app.config
ini-parser database.propertiesSave the parsed JSON output to a file.
Syntax:
ini-parser <file> --output <output-file>
ini-parser <file> -o <output-file>Description:
- Writes formatted JSON to the specified file
- Creates the file if it doesn't exist
- Overwrites the file if it already exists
- Output is still displayed to stdout (unless
--quietis used) - Uses UTF-8 encoding
Example:
ini-parser config.ini --output result.jsonInput file (config.ini):
[database]
host=localhost
port=5432Output file (result.json):
{
"database": {
"host": ["localhost"],
"port": ["5432"]
}
}Expected terminal output:
{
"database": {
"host": ["localhost"],
"port": ["5432"]
}
}Return metadata format with type information.
Syntax:
ini-parser <file> --metaDescription:
- Returns an object with type information for each entry
- Distinguishes between sections and configuration keys
- Useful for building tools that process INI structure
- Each entry includes a
typefield and acontentfield
Example:
ini-parser config.ini --metaInput file (config.ini):
debug=true
[database]
host=localhostExpected output:
{
"debug": {
"type": "configuration",
"content": ["true"]
},
"database": {
"type": "section",
"content": {
"host": {
"type": "configuration",
"content": ["localhost"]
}
}
}
}Type values:
"configuration": Global keys or keys within sections"section": Section entries
Suppress stdout output when saving to file.
Syntax:
ini-parser <file> --output <output-file> --quiet
ini-parser <file> -o <output-file> -qDescription:
- Only works when combined with
--output - Suppresses all stdout output
- File is still written normally
- Useful for scripts and automation
Example:
ini-parser config.ini --output result.json --quietExpected terminal output:
(no output)
Note: The file result.json is still created with the parsed content.
Without --quiet:
ini-parser config.ini --output result.jsonExpected terminal output:
{
"database": {
"host": ["localhost"],
"port": ["5432"]
}
}Check INI file and display statistics without full output.
Syntax:
ini-parser <file> --checkDescription:
- Validates that the file exists and is readable
- Parses the file and counts sections and keys
- Displays success messages with statistics
- Does not output the full parsed JSON
- Exits with code 0 on success, 1 on error
Example:
ini-parser config.ini --checkInput file (config.ini):
[database]
host=localhost
port=5432
[server]
host=0.0.0.0
port=8080Expected output:
[ SUCCESS ] File found: config.ini
[ SUCCESS ] File readable: yes
[ SUCCESS ] Parsed successfully: 2 sections, 4 keys
Example with empty file:
ini-parser empty.ini --checkExpected output:
[ SUCCESS ] File found: empty.ini
[ SUCCESS ] File readable: yes
[ SUCCESS ] Parsed successfully: 0 sections, 0 keys
Output the current version.
Syntax:
ini-parser --version
ini-parser -vDescription:
- Displays the installed version of the CLI
- Exits with code 0
Example:
ini-parser --versionExpected output:
1.0.0
Display help information.
Syntax:
ini-parser --help
ini-parser -hDescription:
- Shows usage information
- Lists all available options
- Displays examples
- Exits with code 0
Example:
ini-parser --helpExpected output:
Usage: ini-parser [options] <file>
Parse INI files into JSON format
Arguments:
file Path to INI file (relative or absolute)
Options:
-v, --version Output the current version
-o, --output <file> Save output to JSON file
--meta Return metadata format with type information
-q, --quiet Suppress stdout output when saving to file
--check Check INI file and display statistics without full output
-h, --help display help for command
Here's a real-world example combining multiple flags for a typical workflow:
Scenario: Parse a complex configuration file with metadata format, save to file, and suppress stdout output.
ini-parser app.ini --meta --output app-config.json --quietInput file (app.ini):
# Application configuration
app_name=MyApp
version=1.0.0
[database]
host=localhost
port=5432
users=
admin
readonly
backup
[server]
host=0.0.0.0
port=8080
allowed_origins=http://localhost:3000 http://localhost:8080Output file (app-config.json):
{
"app_name": {
"type": "configuration",
"content": ["MyApp"]
},
"version": {
"type": "configuration",
"content": ["1.0.0"]
},
"database": {
"type": "section",
"content": {
"host": {
"type": "configuration",
"content": ["localhost"]
},
"port": {
"type": "configuration",
"content": ["5432"]
},
"users": {
"type": "configuration",
"content": ["admin", "readonly", "backup"]
}
}
},
"server": {
"type": "section",
"content": {
"host": {
"type": "configuration",
"content": ["0.0.0.0"]
},
"port": {
"type": "configuration",
"content": ["8080"]
},
"allowed_origins": {
"type": "configuration",
"content": ["http://localhost:3000", "http://localhost:8080"]
}
}
}
}Terminal output:
(no output due to --quiet flag)
Benefits of this combination:
--meta: Preserves type information for later processing--output: Saves result to file for use by other tools--quiet: Clean output for use in scripts or CI/CD pipelines
The CLI uses standard exit codes to indicate success or failure:
Description:
- Command completed successfully
- File was parsed without errors
- Validation passed (with
--check)
Examples:
ini-parser config.ini
# Exit code: 0 (if successful)
ini-parser config.ini --check
# Exit code: 0 (if valid)
ini-parser --version
# Exit code: 0
ini-parser --help
# Exit code: 0Description:
- File not found
- File not readable
- File parsing errors (though parser is resilient)
Examples:
ini-parser nonexistent.ini
# Exit code: 1
# Error: File not found or not readable: nonexistent.ini
ini-parser /path/to/unreadable.ini
# Exit code: 1
# Error: File not found or not readable: /path/to/unreadable.iniDescription:
- Missing required file argument
- Invalid command-line options
- Unknown flags
Examples:
ini-parser
# Exit code: 2
# Error: missing required argument 'file'
ini-parser config.ini --unknown-flag
# Exit code: 2
# Error: unknown option '--unknown-flag'
ini-parser --invalid-option
# Exit code: 2
# Error: unknown option '--invalid-option'Using exit codes in scripts:
#!/bin/bash
ini-parser config.ini --check
if [ $? -eq 0 ]; then
echo "Configuration is valid"
ini-parser config.ini --output config.json
else
echo "Configuration is invalid"
exit 1
fiError message:
[ ERROR ] File not found or not readable: config.ini
Causes:
- File does not exist at the specified path
- Incorrect file path (typo or wrong directory)
- File exists but has no read permissions
Solutions:
- Verify the file exists:
ls config.ini(Unix) ordir config.ini(Windows) - Check the file path is correct
- Use absolute path if relative path is not working
- Verify file permissions:
ls -l config.ini(Unix) - Grant read permissions:
chmod +r config.ini(Unix)
Example:
# Check if file exists
ls config.ini
# Use absolute path
ini-parser /full/path/to/config.ini
# Check permissions (Unix/Linux)
ls -l config.ini
# Should show: -rw-r--r-- or similar with 'r' in user permissionsError message:
[ ERROR ] missing required argument 'file'
Causes:
- No file argument provided
- Command run with only flags
Solutions:
- Always provide a file path as the first argument
- File argument is required even with other flags
Example:
# Incorrect
ini-parser --check
# Correct
ini-parser config.ini --checkError message:
[ ERROR ] unknown option '--invalid-flag'
Causes:
- Typo in option name
- Using an option that doesn't exist
- Wrong flag syntax
Solutions:
- Check spelling of the option
- Use
--helpto see available options - Verify option syntax (single dash for short, double dash for long)
Example:
# Incorrect
ini-parser config.ini --quite # typo
# Correct
ini-parser config.ini --quiet
# Get help
ini-parser --helpError message:
[ ERROR ] Cannot write to file: output.json
Causes:
- No write permissions in target directory
- Directory does not exist
- Disk is full
- File is locked by another process
Solutions:
- Verify directory exists:
ls -d output/(Unix) ordir output\(Windows) - Create directory if needed:
mkdir -p output/(Unix) ormd output\(Windows) - Check write permissions for directory
- Ensure sufficient disk space
- Close any programs that may have the file open
Example:
# Create output directory
mkdir -p output/
# Verify directory exists
ls -d output/
# Try again
ini-parser config.ini --output output/result.jsonini-parser: command not foundSolutions:
-
If installed globally:
- Verify installation:
npm list -g @notfounnd/ini-parser - Reinstall:
npm install -g @notfounnd/ini-parser - Check npm global bin path is in PATH:
npm config get prefix
- Verify installation:
-
If installed locally:
- Use npx:
npx ini-parser config.ini - Or use via npm script in
package.json
- Use npx:
Symptoms:
- Values are split incorrectly
- Comments are included in values
- Multi-line values not recognized
Solutions:
-
Check INI file syntax:
- Use
--checkto validate:ini-parser config.ini --check - Review parsing rules in Parser Rules
- Use
-
Common syntax issues:
- Values with spaces are automatically split (use indented multi-line for paths)
- Semicolons (
;) in values are treated as comments - Indented lines must use spaces or tabs consistently
-
Test with simplified content:
- Create a minimal test file
- Add complexity incrementally
- Identify which line causes issues
Example debugging process:
# 1. Check file is valid
ini-parser config.ini --check
# 2. Parse and review output
ini-parser config.ini
# 3. Try with metadata to see structure
ini-parser config.ini --meta
# 4. Save to file for detailed inspection
ini-parser config.ini --output debug.jsonUnix/Linux:
# Check current permissions
ls -l config.ini
# Add read permission
chmod +r config.ini
# For output directory
chmod +w output/Windows:
# Check file properties
Get-Acl config.ini | Format-List
# Run as administrator if needed
# Right-click terminal and select "Run as administrator"Solutions:
-
Verify input file is valid:
cat config.ini # Unix type config.ini # Windows
-
Check file encoding:
- Ensure input file is UTF-8 encoded
- Some encodings may cause parsing issues
-
Test with minimal file:
echo "[test]" > test.ini echo "key=value" >> test.ini ini-parser test.ini
-
Use
--checkto validate:ini-parser config.ini --check
Causes:
- Terminal doesn't support colors
- Running in environment without TTY
Solutions:
- Use a modern terminal (supports ANSI colors)
- On Windows: Use Windows Terminal, PowerShell, or Git Bash
- Colors are automatically disabled in non-TTY environments (this is normal behavior for logs/files)
- API Reference - Complete API documentation for using the parser programmatically.
- Parser Rules - Detailed documentation on how the parser interprets INI files.
Made with ❤️ by Júnior Sbrissa | Errør 404 | NotFounnd