Monday, 24 April 2017

Node.js - Global Objects

Node.js - Global Objects

Question: How to display the current filename?
console.log(__filename);
This gives you local filename of the current module.



Question: How to display the current directory name?
console.log(__dirname);
This gives you local dirname of the current module.



Question: How to call a function after 5 seconds?
For this, you can use a global function i.e setTimeout.
function helloFunction(){
   console.log( "Hello, World!");
}
/* helloFunction will call after 5 seconds*/
setTimeout(helloFunction, 5000);



Question: How to stop calling a function which was started with setTimeout?
For this, you can use a global function i.e clearTimeout.
function helloFunction(){
   console.log( "Hello, World!");
}
/* helloFunction will call after 5 seconds*/
var funcObj=setTimeout(helloFunction, 5000);

//stop funtion
clearTimeout(funcObj);



Question: How to call a function in every 7 seconds?
For this, you can use a global function i.e setInterval.
function helloFunction(){
   console.log( "Hello, World!");
}
/* helloFunction will call in every 7 seconds*/
setInterval(helloFunction, 7000);



Question: How to stop calling a function which was started with setInterval?
For this, you can use a global function i.e clearInterval
clearInterval(funcObj);



Question: What are different Console Methods to print info, error, warning etc?
  1. console.log: Prints to stdout with newline.
  2. console.error: Prints to stderr with newline.
  3. console.dir: Uses util.inspect on obj and prints resulting string to stdout.
  4. console.time: Mark the time
  5. console.timeEnd: Mark the time end
  6. console.trace: Print to stderr Trace



Question: What are Process Events?
The process object is a global object and can be accessed from anywhere.
process.on('exit', function(code) {   
   console.log('About to exit with code:', code);
});
console.log("Program Ended");



Question: What are different the Process Events?
  1. exit
  2. beforeExit
  3. uncaughtException
  4. Signal Events


Wednesday, 19 April 2017

How to install Zend Framework 2 in wamp using composer?

How to install Zend Framework 2 in wamp using composer?

1. Download the composer


Go to php directory (Path:wamp\bin\php\php5.5.12) from where you can run the PHP commands.
In My Case, I goes to "D:\wamp\bin\php\php5.5.12" using cd commands.
Execute the following command.
php -r "readfile('https://getcomposer.org/installer');" | php



2. Download the Zend framework2 using composer.


You can set the path where you want to download the zf.
I have set the path to "D:/wamp/www/zf2", Please change this as per ur need.
Execute the following command.
php composer.phar create-project -sdev --repository-url="https://packages.zendframework.com" zendframework/skeleton-application "D:/wamp/www/zf2"
 


3. Virtual Host Setup


Add following code in httpd-vhosts.conf file.
My Local path: D:\wamp\bin\apache\apache2.4.9\conf\extra
<VirtualHost *:80>
    DocumentRoot "D:\wamp\www\zf2\public"
    ServerName zf2.loc
    <Directory "D:\wamp\www\zf2\public">
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>


Add following code in hosts file
My Local path is : C:\Windows\System32\drivers\etc
127.0.0.1       zf2.loc

4. ReStart wamp Server


4. Open http://zf2.loc/

It must working, if not please comment. We let u know the reason.