Giter Club home page Giter Club logo

node-cli-example's Introduction

node-cli-example

CI

This project is just example of parsing nginx access log to JSON or vice versa using CLI on Node.js

Access Log Format

$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $gzip_ratio

Command Usage

$ cli -h

Options:
      --version  Show version number                                   [boolean]
  -t, --type     Output type                                            [string]
  -o, --output   Output file name                                       [string]
  -h, --help     Show help                                             [boolean]

Example Converting log file to JSON file

$ cli.js ../samples/access.log -t json -o /tmp/access.json

Converting to JSON file
Saving json file proceeded to: /tmp/access.json

$ cat /tmp/access.json

[
  {
    "remote_addr": "47.29.201.179",
    "remote_user": "-",
    "time_local": "[28/Feb/2019:13:17:10 +0000]",
    "request": "GET /?p=1 HTTP/2.0",
    "status": 200,
    "body_bytes_sent": 5316,
    "http_referer": "https://domain1.com/?p=1",
    "http_user_agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
    "gzip_ratio": "2.75"
  },
  ...
]

Example Converting JSON file to log file

$ cli.js /tmp/access.json -t text -o /tmp/access.log      

Converting to text file
Saving text file proceeded to: /tmp/access.log

$ cat /tmp/access.log

47.29.201.179 - - [28/Feb/2019:13:17:10 +0000] "GET /?p=1 HTTP/2.0" 200 5316 "https://domain1.com/?p=1" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "2.75"
47.29.201.179 - - [28/Feb/2019:13:17:10 +0000] "GET /?p=2 HTTP/2.0" 200 5316 "https://domain1.com/?p=2" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "2.75"
47.29.201.179 - - [28/Feb/2019:13:17:10 +0000] "GET /?p=3 HTTP/2.0" 200 5316 "https://domain1.com/?p=3" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "2.75"
...

node-cli-example's People

Contributors

lutfailham96 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.