Skip to content

Instantly share code, notes, and snippets.

@marta-krzyk-dev
Last active May 1, 2019 10:16
Show Gist options
  • Save marta-krzyk-dev/98ea6c90e9861009673dc27af82f63cb to your computer and use it in GitHub Desktop.
Save marta-krzyk-dev/98ea6c90e9861009673dc27af82f63cb to your computer and use it in GitHub Desktop.
Debugging in Node JS with debug
/*
* Simple debug example in Node JS :)
*
*/
// 1. Install debug in the folder where your app lives
// npm install debug --save
// 2. Copy and paste this line to your js file to your dependencies, then use debug('My comments'); in your code
// var debug = require('debug')('my_debug_name');
// 3. Execute the app in command line like so:
// for Windows:
// set DEBUG=* & node debugApp.js
// for MAC, Linux
// NODE_DEBUG=my_debug_name node debugApp.js
// Show messages for all debugs:
// set DEBUG=* & node debugApp.js
// Show messages for some debugs:
// set DEBUG=dolphin,flowers & node debugApp.js
// Dependencies
var debug1 = require('debug')('dolphin');
var debug2 = require('debug')('flowers');
swimDolphin = function(){
debug1('The dolphin is swimming graciously!');
};
pickUpFlowers = function(){
debug2('Fairy is picking up gorgeous flowers!');
};
swimDolphin();
pickUpFlowers();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment