DEV Community

Giuseppe Zileni
Giuseppe Zileni

Posted on

logbootstrap

During a developer's work on a nodejs application are often used console.log to visualize the progress of code at critical points, for quick debugging, or to display any warnings and errors in your code.

The logbootstrap module is very simple because it allows you to use colored log messages. The colors available are the same as in the BootStrap tool kit:

  • green : successful message
  • yellow: for a warning
  • cyan: a simple piece of information
  • gray: a secondary message
  • blue: a very important primary message
  • red: error message

Let's create a simple nodejs application:

$ mkdir ~/helloworld
$ cd ~/helloword
$ npm init
$ npm install logbootstrap
$ nano index.js
Enter fullscreen mode Exit fullscreen mode

the index file.js will be a simple Endpoint API with the most classic "Hello World!"

const http = require('http');
const log = require('logbootstrap);

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!\n');
});

server.listen(port, hostname, () => {
  log('info', 'Server running at http://' + hostname + ':' + port + '/');
  log('success', 'Success log information');
  log('warning', 'Warning log information');
  log('secondary', 'Secondary log information');
  log('primary', 'Primary log information');
  log('danger', 'Danger log information');
});
Enter fullscreen mode Exit fullscreen mode

We run the code:

Alt Text

Good Colorful Code !

GitHub Projects: https://gzileni.github.io/logbootstrap/

Top comments (0)