Skip to content

Quickstarts : Using Command Line

1. Processing Single User-Agent String

You can use npx🡥 to run UAParser.js directly from the command line without installing it globally:

npm
sh
$ npx ua-parser-js "<INSERT-USER-AGENT-HERE>"
Console
sh
# example command input:
npx ua-parser-js "Flock/2.16 (Zenwalk 7.3; es_PR;)"

# console output:
[
    {
        "ua": "Flock/2.16 (Zenwalk 7.3; es_PR;)",
        "browser": {
            "name": "Flock",
            "version": "2.16",
            "major": "2"
        },
        "cpu": {},
        "device": {},
        "engine": {},
        "os": {
            "name": "Zenwalk",
            "version": "7.3"
        }
    }
]

# let's save the result into a log file:
npx ua-parser-js "Flock/2.16 (Zenwalk 7.3; es_PR;)" >> log.txt

2. Processing Batch User-Agent Data from File

You can also parse multiple User-Agent strings from a file and exporting the results as JSON. This is useful for bulk analysis, log processing, or offline User-Agent parsing.

Console
sh
npx ua-parser-js --input-file log.txt --output-file log-result.json
OptionDescription
--input-filePath to a text file containing User-Agent strings (one per line).
--output-filePath to the JSON file where parsed results will be saved.

UAParser.js v2 is licensed under AGPLv3 or PRO licenses.