Sakshi Tyagi

Full stack software developer

Technology

Sandboxing In Node.JS Using VM Module

Two commonly known ways to execute a script in Node.JS are using eval () function or running it using VM module. Lets see this through an example: [js] var vm = require('vm'); this.name = "Sakshi"; var script = "this.name = 'Tyagi'", withVM, withEVAL; withEVAL = eval(script); console.log("withEVAL...

24-Jan-2014

Technology

Digging Into Event Emitters In Node.JS

In extension to my previous blog on Event Emitters Event Emitters In Node.JS, here we will see some variations in implementing Event Emitters. We can bind more than one listeners to an event. For example: [js] var events = require('events'); var eventEmitter = new events.EventEmitter(); var printFruit = function printFruit() { ...

23-Jan-2014

Technology

Constants In JavaScript

We can create constants in JavaScript using 'const' keyword. [js] const name = 'Sakshi' console.log(name) [/js] This will print: Sakshi Now, if we try to change or re-initialize 'name' constant, the value will not change. [js] const name = 'Hello' console.log(name) [/js] This will again print: Sakshi Compatibility: 'const'...

22-Jan-2014

Technology

Event Emitters In Node.JS

Event Emitters are used to create and manage our own events and trigger them accordingly. We can bind listeners and emit those events whenever required. Example : [js] var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('Morning', function welcomeMessage() { console.log('Good...

03-Jan-2014

Technology

How to Determine Average in MongoDB

MongoDB provides several ways of computing the average value of a group in a collection. One of the simplest ways of determining average is using the method db.collection.group(). The method db.collection.group() bunches the documents of a collection on the basis of the keys mentioned and executes aggregation functions on them. This...

02-Apr-2013

Technology

Difference Between ‘null’ and ‘undefined’ in JavaScript

Most people using JavaScript misunderstand the difference between ‘null’ and ‘undefined’. An unclear distinction between these two entities can lead to grave issues when using ‘null’ and ‘undefined’ in test cases. A variable is said to be ‘undefined’ if it has been declared, but no value has been given to it....

01-Mar-2013

Node.js

How to Remove Duplicate Elements from Array in JavaScript

Arrays in JavaScript are daunting and particularly difficult in nature. The fundamental reason for making this statement is that JavaScript does not provide as many functions/methods for array operations as several other languages do. As a result, an array operation as simple as removing duplicate elements from an array may also be...

01-Feb-2013