0.3.2 • Published 4 years ago

csb-inspector v0.3.2

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

CSB-INSPECTOR

View complete Documentation

Introduction

Many times when developing an application with a Backend written in NodeJs, we tend to send many messages into the terminal “console.log (data)” to help us to keep track of the state of our application, at some point we find tedious to search that printing in the terminal, in some cases we are even mistaken in printing, in some cases we want to identify which file and line of code where that screen printing “console.log (data)” is running because NodeJs only prints the arguments that we pass and does not refer to which file and or in which line of code that print was executed.

csb-inspector is a library that identifies the file and code line where the “console.log (data)” screen printing is being executed and shows us the reference of where the printing is being executed.

If we see the previous image, we can see the reference to the file and line of code that print in the terminal belongs to.

Instalation

We go to our terminal and in the folder of our NodeJs project we install the dependency.

    $ npm install --save csb-inspector

Terminal

csb-inspector

In the main file of your nodejs application write this code

    const CsbInspector = require('csb-inspector');
    CsbInspector();

This is the simplest implementation, which helps to display the file and the line of code in the terminal.

Options

    const CsbInspector = require('csb-inspector');
    CsbInspector({
      outputs: [
        (path, key, args, date)=> {
          // path:  "reference to file",
          // key: "type of console, 'log', 'error'",
          // args: 'arguments',
          // date: 'Object Date, When execute console'
        }
      ]
    });

Description

OptionsDescriptionRequiredDefault
outputsArray of functions that receive 4 parameters, which allows us to extend the functionality of the libraryfalse-

As we can see, we send you an object with an “outputs” property. It contains an array of functions that receive 4 parameters.

This property helps us to extend the functionality of this library, obtaining those parameters we could save them in a file or other options that we consider useful. This parameter is not required. This implementation will be useful for any NodeJs server.

Terminal and Express

csb-inspector/express-socket

The csb-inspector library provides a control panel that shows in the browser in real-time the prints in the terminal "console.log (data)" with its respective reference to the file and line of code and also displays the occurrence time. This functionality can be implemented for applications based on ExpressJs.

This code must be in the file where the server is initialized with ExpressJs.

  const express = require('express');
  const app = express();

  const CsbInspector = require('csb-inspector/express-socket');
  const options = {
      app: app
  }

  CsbInspector(options);

ServerPort - Is the port where the server is running

Open your browser and load 'http://localhost:{ServerPort}/_console'

Options

The library allows us to configure it according to our environment.

  const express = require('express');
  const app = express();

  const CsbInspector = require('csb-inspector/express-socket');
  const options = {
      app: app,
      route: "debugger_logs",
      port: 8888,
      host: "http://192.16.3.89",
      disabledBrowser: false,
      outputs: [
        (path, key, args, date)=> {
          // path:  "reference to file",
          // key: "type of console, 'log', 'error'",
          // args: 'arguments',
          // date: 'Object Date, when execute console'
            fs.appendFileSync("file.txt", path);
        }
      ]
    }
  CsbInspector(options);

Description

OptionsDescriptionRequiredDefault
appExpress applicationtrue-
routeRoute where the control panel will be displayedfalse_console
hostHost of Serverfalse'http://localhost'
portPort through the socket listensfalse8888
disabledBrowserDisable control panel in browserfalsefalse
outputsArray of functions that receive 4 parameters, which allows us to extend the functionality of the libraryfalse-

Open your browser and load URL 'http://192.16.3.89:{ServerPort}/debugger_logs'.

URL - Built with the above parameters.

ServerPort - Is the port where the server is running.

We code

Browser

Terminal

Feedback

Find a bug or have a feature request? Please file an issue!

Contact

Follow @adrzelada

Adrian Pedro Zelada Torrez

Medium: @adrianpedrozeladatorrez.

Email: zelada.torreza@gmail.com

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.123

4 years ago

0.1.122

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.121

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago