Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
// Import events module
var events = require('events');
// Create an eventEmitter object
var eventEmitter = new events.EventEmitter();
// Create an event handler as follows
var connectHandler = function connected() {
console.log('connection succesful.');
// Fire the data_received event
eventEmitter.emit('data_received');
}
// Bind the connection event with the handler
eventEmitter.on('connection', connectHandler);
// Bind the data_received event with the anonymous function
eventEmitter.on('data_received', function(){
console.log('data received succesfully.');
});
// Fire the connection event
eventEmitter.emit('connection');
console.log("Program Ended.");
/* Simple Hello World in Node.js */
var resp = {};
resp.json = "{test}";
resp.html = "test";
console.log(resp);
//base64 to hex
var idStr = "Dev:Devuser@1234";
var buffer = new Buffer(idStr, 'base64');
var toHex = buffer.toString('hex');
console.log("Encode: " + toHex);
//base64 to string
var b = new Buffer('RGV2OkRldnVzZXJAMTIzNA==', 'base64')
var s = b.toString('utf8');
console.log("Decode: " +s);
//string to base64 convertion
var idStr = "Dev:Devuser@1234";
var buffer = new Buffer(idStr, 'utf8');
var toHex = buffer.toString('base64');
console.log("Encode: " + toHex);
/* Simple Hello World in Node.js */
var testStr = "going again to modifiy going again";
//var repStr = testStr.replace(/going/gi, "coming");
var rs1 = "going";
var rep_regex = new RegExp(rs1,"gi");
var str_rep = testStr.replace(rep_regex,"devaraj");
console.log(str_rep);