Saturday, June 3, 2017

Sister is very special




 πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§


  πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§πŸ‘§

Node.js Modules






 πŸ’₯What is Modules?

A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file.

 πŸ’₯How to create Module

πŸ‘‰Create a module that returns the current date and time:

        πŸ‘Šexports.myDateTime = function () {
    return Date();
}; 
   πŸ‘‰Save the code above in a file called "firstmodule.js"
 πŸ‘‰Now we  can include and use the module in any of our Node.js files.
 
    πŸ‘Š var http = require('http');
var dt = require('./myfirstmodule');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write("The date and time is currently: " + dt.myDateTime());
    res.end();
}).listen(8080);
 
 πŸ‘‰Save the code above in a file called "demo_module.js", and initiate the file
 
πŸ‘‰Initiate demo_module.js in Terminal
      C:\Users\Your Name> node demo_module.js 
 
πŸ‘‰ If we want result,We will use this path http://localhost:8080

πŸ’₯ Node.js HTTP Module

      πŸ‘‰This allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP).

         πŸ‘Š var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the server object listens on port 8080


     πŸ‘‰Save the code above in a file called "demo_http.js"
      πŸ‘‰then use below code in terminal
          C:\Users\Your Name>node demo_http.js
          
          πŸ‘‰ Then use port to open browser
                out put:
                          
                       Hello World!

 πŸ’₯Node.js URL Module

πŸ‘‰Create two html files and save them in the same folder as your node.js files.

    πŸ‘Švar http = require('http');
var url = require('url');
var fs = require('fs');

http.createServer(function (req, res) {
  var q = url.parse(req.url, true);
  var filename = "." + q.pathname;
  fs.readFile(filename, function(err, data) {
    if (err) {
      res.writeHead(404, {'Content-Type': 'text/html'});
      return res.end("404 Not Found");
    } 
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });
}).listen(8080); 


πŸ‘‰ node demo_fileserver.js 

πŸ‘‰http://localhost:8080/(htmlfilename)






Nodejs introduction

πŸ’₯What is Node.js


πŸ˜… Node.js is an open source server framework
πŸ˜… Node.js is free
πŸ˜… Node.js runs on various platforms (Windows, Linux, Unix)
πŸ˜… Node.js uses JavaScript on the server

 πŸ’₯What are the different between Node.js & PHP or ASP

       πŸ’¦how is  PHP or ASP handles a file request

             πŸ˜…Sends the task to the computer's file system.
             πŸ˜…Waits while the file system opens and reads the file.
             πŸ˜…Returns the content to the client.
             πŸ˜…Ready to handle the next request.



      πŸ’¦how is Node.js handles a file request
 
            πŸ˜…Sends the task to the computer's file system.
            πŸ˜…Ready to handle the next request.
            πŸ˜…When the file system has opened and read the file, the server returns the content to the client.

πŸ’₯What are the functions in Node.js?


    πŸ˜…Node.js can generate dynamic page content
    πŸ˜…Node.js can create, open, read, write, delete, and close files on the server
   πŸ˜…Node.js can collect form data
   πŸ˜…Node.js can add, delete, modify data in your database

πŸ’₯ Node.js files have extension ".js"

Friday, June 2, 2017

Mongo db Install

πŸ’₯ How to install Mongodb

      πŸ’’ Start MongoDB


                     πŸ‘€ sudo service mongodb start

       πŸ’’ Stop MongoDB


                    πŸ‘€ sudo service mongodb stop

          πŸ’’ Restart MongoDB


                     πŸ‘€ sudo service mongodb restart
 
  πŸ’₯ To use MongoDB run the following command.


                       πŸ‘€ mongo
 
 
  πŸ’₯How to create database

            πŸ’§If you want to create a database with name <mydb>, then use database statement would be as follows 


>use mydb
switched to db mydb
 
           πŸ’§To check your currently selected database, use the command db


>db
mydb
 
            πŸ’§If you want to check your databases list, use the command show dbs.


>show dbs
local     0.78125GB
test      0.23012GB
 
           πŸ’§Your created database (mydb) is not present in list. To display database, you need to insert at least one document into it.


>db.student.insert({"name":"Abi"})
>show dbs
local      0.78125GB
mydb       0.23012GB
test       0.23012GB
 
      
  πŸ’₯ How to drop Database
 
 
Basic syntax of dropDatabase() command is as follows −
πŸ’₯db.dropDatabase() 

          πŸ’§This will delete the selected database. If you have not selected any database, then it will delete default 'test' database.


     πŸ‘‰First, check the list of available databases by using the command, show dbs.

      πŸ’§>show dbs
 local 0.78125GB 
mydb 0.23012GB 
 test 0.23012GB 
 
      πŸ‘‰If you want to delete new database <mydb>, then dropDatabase() command would be as follows 

    πŸ’§>use mydb switched to db mydb  
     > db.dropDatabase() 
     >{ "dropped" : "mydb", "ok" : 1 } >
 
       πŸ‘‰Now check list of databases.

>show dbs 
 local 0.78125GB 
test 0.23012GB >

MongoDB



            πŸ’₯ MongoDB is an open-source document database and leading NoSQL database

            πŸ’₯ MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.


πŸ’₯ Advantages of MongoDB over RDBMS

  • Schema less − MongoDB is a document database in which one collection holds different documents. Number of fields, content and size of the document can differ from one document to another.
  • Structure of a single object is clear.
  • No complex joins.
  • Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL.
  • Tuning.
  • Ease of scale-out − MongoDB is easy to scale.
  • Conversion/mapping of application objects to database objects not needed.
  • Uses internal memory for storing the (windowed) working set, enabling faster access of data.


    πŸ’₯ Why Use MongoDB?

  • Document Oriented Storage − Data is stored in the form of JSON style documents.
  • Index on any attribute
  • Replication and high availability
  • Auto-sharding
  • Rich queries
  • Fast in-place updates
  • Professional support by MongoDB

 πŸ’₯ Where to Use MongoDB?

  • Big Data

  • Content Management and Delivery

  • Mobile and Social Infrastructure

  • User Data Management

  • Data Hub



Thursday, June 1, 2017

jQuery Event


   πŸ’₯ All the different visitor's actions that a web page can respond to are called events.

  πŸ’₯  An event represents the precise moment when something happens.
Examples:
  • moving a mouse over an element
            πŸ’§<script>
$(document).ready(function(){
    $("p").on({
        mouseenter: function(){
            $(this).css("background-color", "lightgray");
        }, 
        mouseleave: function(){
            $(this).css("background-color", "lightblue");
        },
        click: function(){
            $(this).css("background-color", "yellow");
        } 
    });
});
</script>

  • selecting a radio button
           πŸ’§<script>
$(document).ready(function(){
    $("input").keypress(function(){
        $(this).hide();
    });
});
</script>

  • clicking on an element

  •        πŸ’§<script>
    $(document).ready(function(){
        $("p").on("click", function(){
            $(this).hide();
        });
    });
    </script>

jQuery




πŸ’₯ jQuery is a JavaScript Library.

πŸ’₯  jQuery greatly simplifies JavaScript programming.  
πŸ’₯ The purpose of jQuery is to make it much easier to use JavaScript on your website.

πŸ’¦ jQuery Syntax

Basic syntax is: $(selector).action()
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)
 
 

πŸ’¦ jQuery Selectors

      πŸ‘¦The element Selector

              You can select all <p> elements on a page like this:
$("p") 
 
 
    πŸ‘¦The  #id selector

      An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
$("#test") 
 
     πŸ‘¦ The . class selector

     To find elements with a specific class, write a period character, followed by the name of the class:
$(".test")