Posts

Showing posts with the label nodejs

Selenium Webdriver in Nodejs + Javascript

Phewww getting back to blog after almost an year. So, am back to discuss an interesting node module selenium-webdriver [Ref: Project Doc and npm registry ] Am assuming the reader has prior knowledge on what nodejs , npm and node modules are. And a little bit of selenium fun ;) What is selenium? As wiki says, Selenium is a portable software testing framework for web applications. It is a prominently used tool for browser automation. For further details checkout SeleniumHQ . What are we doing here? Basically Selenium provides bindings in many languages like java, python, php and now even nodejs. Here am planning to run through few code samples of using selenium webdriver in nodejs. Where to start? im@mylaptop$ npm install --save selenium-webdriver A Simple Webdriver Example // Import Selenium Dependency var Webdriver = require('selenium-webdriver'); // Few Settings var PAGE_LOAD_TIMEOUT_MS = 10000; var SCRIPT_LOAD_TIMEOUT_MS = 1000; var WINDOW_WIDTH_PX = 1024; v...

GRUNT- The JavaScript Task Runner

Image
Grunt helps developers automate the task of javascript deployment. In our development cycle, every javascript deployment used to be 1. Code 2. Minify 3. Upload We were missing out two important phases which ensures code quality and reliability 1. Lint 2. Testing As our code became larger and larger, as anyother dev we also considered a refactor. The refactor resulted in splitting our large code base to manageable modules. Now, Deployment has to go through 1. Unit test independent modules 2. Merge Modules to a shippable target 3. Lint 4. Minify 5. Deploy Ooops... Nice but how? It's true that developers love things automated, and so we were. We arrived at a one stop solution GRUNT. This blog post is a Let Them Know Types. As, I felt that the instructions on grunt setup is kind of scattered :) To hav a better introduction with the hero, you should meet him at his place Grunt has two parts: 1. Using it 2. Customizing it How to start using it? Installation: G...

Asynchronous Javascript & jQuery Deferred Why?

Using jQuery Deferred In this post I'll try to cover an overview of promises and deferred. Further how to use them in nodejs. Define Deferred? Google Define: Put off (an action or event) to a later time; postpone Deferred in javascript? Javsacript being an event driven scripting [and a developing programming] language, there is obvious need for developers to defer things awaiting events. For ex: window.addEventListner("load", function () { console.log("Defer my execution till window load"); }, false); $.ajax({ url: 'data.html', success: function () { console.log("Defer my execution till ajax load is successful") }, error: function () { console.log("Defer my execution till ajax load fails") } }); So? This is nothing unusual!!! Ya, obviously it is nothing unusual and obviously a beginner level fact. Deferred: As a programming paradigm, is a design pattern which solves the problem of code nea...

npm - package manager for node and package.json a overview

npm: node package manager [!an acronym :P] Till the time I got to know about this guy, code upload across servers use to be a tough task. He is the one to look out incase you are to develop an application in node and host it across servers package.json is his weapon ;) In this article I'm just planning to touch npm basics and use of package.json and it is tl;dr ;) What is npm? From here : npm is a package manager for node. You can use it to install and publish your node programs. It manages dependencies and does other cool stuff. Basically node uses commonjs style module system. Every module is an independent piece of javascript code which can be plugged in and out of the core of your application. Modules can be custom built or built for a generic purpose like redis, mysql, async, log4js. And it will be always good to know if there are any pre-built modules available for our need before we start building our own. npm does it for you like a charm :) How do I instal...

Nodejs Modules and Export Explained

Enjoyed a week playing around with nodejs :) Lets share Simple Node Server [http://localhost:6666]: var http = require('http'); var server = http.createServer(function (req, res) {            // Do Whatever you want               res.writeHead(200, {'Content-Type':'text/plain'});               res.end('Running');          }).listen(6666, function () {                    console.log('Node Runs on port 6666'); }); How to install a node_module? NPM is a powerful package manager for node which you can use to install node modules Ex: npm install redis The above command installs redis module in ./node_modules/redis directory How to use a module? Use require() method Ex: require('redis') How will node resolve the modules? Consider /home/xxx/sample  |___ index.js  |___ node_modules...