CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

17 June, 2019

How to Import and Export CSV Files Using PHP and MySQL

 Programing Coderfunda     June 17, 2019     php     No comments   

<?php
session_start();
error_reporting(0);
include('includes/config.php');
include('includes/sessionout.php');
if(strlen($_SESSION['alogin'])==0)
    {  
header('location:index.php');
}
else{

$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// $success = 1 ;
// $error = 2;

$msg = "CSV Data Imported into the Database";
 $error = "Problem in Importing CSV Data";
 $errors = "No csv file selected";
if (isset($_POST["import"])) {
   

    $fileName = $_FILES["file"]["tmp_name"];
    if ($_FILES["file"]["size"] > 0) {
       
        $file = fopen($fileName, "r");
       
        while (($column = fgetcsv($file, 10000, ",")) !== FALSE) {
          $sqlInsert = "INSERT into lms_master (custid,FirstName ,EmailId,Gender,Dob,Address,    C_Address,City,state,pincode,Mobile,LastStatus,RegDate,LastCall,Remark,Csv_Date)
                   values ('" . $column[0] . "','" . $column[1] . "','" . $column[2] . "','" . $column[3] . "','" . $column[4] . "','" . $column[5] . "','" . $column[6] . "','" . $column[7] . "','" . $column[8] . "','" . $column[9] . "','" . $column[10] . "','" . $column[11] . "','" . $column[12 ] . "','" . $column[13] . "','" . $column[14] . "','" . $column[15] . "')";
            $result = mysqli_query($conn, $sqlInsert);
           
            if ($result) {
                $type = "success";
                header("Location: upload_data.php?success=1");
            } else {
                $type = "error";
                header("Location: upload_data.php?error=2");
            }
        }
    }else{
        $type = "error";
                $errors = "No csv file selected";
                header("Location: upload_data.php?errors=3");
    }
}

?>

<!DOCTYPE html>
<html lang="en">
    <head>       
        <!-- Title -->
        <title>Admin | Import Data</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
        <meta charset="UTF-8">
        <meta name="description" content="Responsive Admin Dashboard Template" />
        <meta name="keywords" content="admin,dashboard" />
        <meta name="author" content="Steelcoders" />
        <!-- Styles -->
        <link type="text/css" rel="stylesheet" href="../assets/plugins/materialize/css/materialize.min.css"/>
        <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link href="../assets/plugins/material-preloader/css/materialPreloader.min.css" rel="stylesheet">
        <link href="../assets/css/alpha.min.css" rel="stylesheet" type="text/css"/>
        <link href="../assets/css/custom.css" rel="stylesheet" type="text/css"/>
       
        <style>
            .errorWrap {
            padding: 10px;
            margin: 0 0 20px 0;
            background: #fff;
            border-left: 4px solid #dd3d36;
            -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
            box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
            }
            .succWrap{
                padding: 10px;
                margin: 0 0 20px 0;
                background: #fff;
                border-left: 4px solid #5cb85c;
                -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
                box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
            }
        </style>
    </head>
    <body>
  <?php include('includes/header.php');?>
       <?php include('includes/sidebar.php');?>
            <main class="mn-inner">
                <div class="row">
                    <div class="col s12">
                        <div class="page-title"></div>
                    </div>
                    <div class="col s12 m12 l6">
                        <div class="card">
                            <div class="card-content">
                                <div class="row">
                                    <div class="imp_data">
                                    <span class="card-title"><a href="dashboard.php">Dashboard</a>&nbsp;>&nbsp;Employee&nbsp;|&nbsp;Import&nbsp;Data</span>

                                    </div>
                                    <form class="col s12" name="chngpwd" method="post" enctype="multipart/form-data">
                                          <?php if($_GET['error'] == 2 ){?>
                                                <div class="errorWrap">
                                                 <strong>ERROR</strong> : <?php echo htmlentities($error); ?>
                                                </div><?php }
                                                    else if($_GET['success'] == 1){?><div class="succWrap">
                                                    <strong>SUCCESS</strong> : <?php echo htmlentities($msg); ?>
                                                </div>
                                            <?php }?>

                                            <?php if($_GET['errors'] == 3 ){?>
                                                <div class="errorWrap">
                                                 <strong>ERROR</strong> : <?php echo htmlentities($errors); ?>
                                                </div><?php }
                                                    else if($_GET['success'] == 4){?><div class="succWrap">
                                                    <strong>SUCCESS</strong> : <?php echo htmlentities($msg); ?>
                                                </div>
                                            <?php }?>
                                           
                                           
                                        <div class="row">
                                            <div class="input-row">
                                                    <label class="col-md-4 control-label"></label> <input
                                                        type="file" name="file" id="file" accept=".csv">
                                                    <button type="submit" id="submit" name="import"
                                                        class="btn-submit">Import</button>
                                                    <br/>
                                                     <div id="labelError"></div>
                                                </div>
                                                <div id="labelError"></div>
                                            </div>   
                                        </div>
                                    </form>
                                </div>
                            </div>
                         <section>
                                <?php
                                        $sqlSelect = "SELECT * FROM lms_master";
                                        $result = mysqli_query($conn, $sqlSelect);
                                                   
                                        if (mysqli_num_rows($result) > 0) {
                                        ?>
                                        <table id='userTable'>
                                            <thead>
                                                <tr>
                                                    <th>First Name</th>
                                                    <th>EmailId</th>
                                                    <th>Gender</th>
                                                    <th>Dob</th>
                                                    <th>Address</th>
                                                    <th>C_Address</th>
                                                    <th>City</th>
                                                    <th>state</th>
                                                    <th>pincode</th>
                                                    <th>Mobile</th>
                                                    <th>LastStatus</th>
                                                    <th>LastCall</th>
                                                    <th>Remark</th>
                                                    <th>CSV Date</th>
                                                </tr>
                                            </thead>
                                            <?php
                                            while ($row = mysqli_fetch_array($result)) {
                                            ?>
                                            <tbody>
                                                <tr>
                                                    <td><?php  echo $row['FirstName ']; ?></td>
                                                    <td><?php  echo $row['EmailId ']; ?></td>
                                                    <td><?php echo $row['Gender']; ?></td>
                                                    <td><?php  echo $row['Dob']; ?></td>
                                                    <td><?php  echo $row['Address']; ?></td>
                                                    <td><?php  echo $row['C_Address']; ?></td>
                                                    <td><?php  echo $row['City']; ?></td>
                                                    <td><?php  echo $row['state']; ?></td>
                                                    <td><?php  echo $row['pincode']; ?></td>
                                                    <td><?php  echo $row['Mobile']; ?></td>
                                                    <td><?php  echo $row['LastStatus']; ?>
                                                    </td>        
                                                    <td><?php  echo $row['LastCall']; ?></td>
                                                    <td><?php  echo $row['Remark']; ?></td>
                                                    <td><?php  echo $row['Csv_Date']; ?></td>
                                                </tr>
                                             <?php
                                             }
                                             ?>
                                            </tbody>
                                        </table>
                                        <?php } ?>
                            </section> 
                        </div>
                    </div>
                    <!-- start second part right -->
                    <section>
                    </section>
                </div>
            </main>
        </div>
        <div class="left-sidebar-hover"></div>
        <!-- Javascripts -->
        <script src="../assets/plugins/jquery/jquery-2.2.0.min.js"></script>
        <script src="../assets/plugins/materialize/js/materialize.min.js"></script>
        <script src="../assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
        <script src="../assets/plugins/jquery-blockui/jquery.blockui.js"></script>
        <script src="../assets/js/alpha.min.js"></script>
        <script src="../assets/js/pages/form_elements.js"></script>
        <!-- Import CSV File -->
        <script type="text/javascript">
            <script type="text/javascript">
        $(document).ready(
            function() {
            $("#frmCSVImport").on(
            "submit",
            function() {
            $("#response").attr("class", "");
            $("#response").html("");
            var fileType = ".csv";
            var regex = new RegExp("([a-zA-Z0-9\s_\\.\-:])+("
                    + fileType + ")$");
            if (!regex.test($("#file").val().toLowerCase())) {
                $("#response").addClass("error");
                $("#response").addClass("display-block");
                $("#response").html(
                        "Invalid File. Upload : <b>" + fileType
                                + "</b> Files.");
                return false;
            }
            return true;
        });
    });
</script>
        </script>
    </body>
</html>
<?php } ?>


<!-- start csv file
 -->
 <?php 
$connect = mysqli_connect("localhost", "root", "", "testing");
if(isset($_POST["submit"]))
{
 if($_FILES['file']['name'])
 {
  $filename = explode(".", $_FILES['file']['name']);
  if($filename[1] == 'csv')
  {
   $handle = fopen($_FILES['file']['tmp_name'], "r");
   while($data = fgetcsv($handle))
   {
    $item1 = mysqli_real_escape_string($connect, $data[0]); 
                $item2 = mysqli_real_escape_string($connect, $data[1]);
                $query = "INSERT into excel(excel_name, excel_email) values('$item1','$item2')";
                mysqli_query($connect, $query);
   }
   fclose($handle);
   echo "<script>alert('Import done');</script>";
  }
 }
}
?> 
<!DOCTYPE html> 
<html> 
 <head> 
  <title>Webslesson Tutorial</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
 </head> 
 <body> 
  <h3 align="center">How to Import Data from CSV File to Mysql using PHP</h3><br />
  <form method="post" enctype="multipart/form-data">
   <div align="center"> 
    <label>Select CSV File:</label>
    <input type="file" name="file" />
    <br />
    <input type="submit" name="submit" value="Import" class="btn btn-info" />
   </div>
  </form>
 </body> 
</html>

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to Import and Export CSV Files Using PHP and MySQL

 Programing Coderfunda     June 17, 2019     php     No comments   

<?php
session_start();
error_reporting(0);
include('includes/config.php');
include('includes/sessionout.php');
if(strlen($_SESSION['alogin'])==0)
    {  
header('location:index.php');
}
else{

$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// $success = 1 ;
// $error = 2;

$msg = "CSV Data Imported into the Database";
 $error = "Problem in Importing CSV Data";
 $errors = "No csv file selected";
if (isset($_POST["import"])) {
   

    $fileName = $_FILES["file"]["tmp_name"];
    if ($_FILES["file"]["size"] > 0) {
       
        $file = fopen($fileName, "r");
       
        while (($column = fgetcsv($file, 10000, ",")) !== FALSE) {
          $sqlInsert = "INSERT into lms_master (custid,FirstName ,EmailId,Gender,Dob,Address,    C_Address,City,state,pincode,Mobile,LastStatus,RegDate,LastCall,Remark,Csv_Date)
                   values ('" . $column[0] . "','" . $column[1] . "','" . $column[2] . "','" . $column[3] . "','" . $column[4] . "','" . $column[5] . "','" . $column[6] . "','" . $column[7] . "','" . $column[8] . "','" . $column[9] . "','" . $column[10] . "','" . $column[11] . "','" . $column[12 ] . "','" . $column[13] . "','" . $column[14] . "','" . $column[15] . "')";
            $result = mysqli_query($conn, $sqlInsert);
           
            if ($result) {
                $type = "success";
                header("Location: upload_data.php?success=1");
            } else {
                $type = "error";
                header("Location: upload_data.php?error=2");
            }
        }
    }else{
        $type = "error";
                $errors = "No csv file selected";
                header("Location: upload_data.php?errors=3");
    }
}

?>

<!DOCTYPE html>
<html lang="en">
    <head>       
        <!-- Title -->
        <title>Admin | Import Data</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
        <meta charset="UTF-8">
        <meta name="description" content="Responsive Admin Dashboard Template" />
        <meta name="keywords" content="admin,dashboard" />
        <meta name="author" content="Steelcoders" />
        <!-- Styles -->
        <link type="text/css" rel="stylesheet" href="../assets/plugins/materialize/css/materialize.min.css"/>
        <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link href="../assets/plugins/material-preloader/css/materialPreloader.min.css" rel="stylesheet">
        <link href="../assets/css/alpha.min.css" rel="stylesheet" type="text/css"/>
        <link href="../assets/css/custom.css" rel="stylesheet" type="text/css"/>
       
        <style>
            .errorWrap {
            padding: 10px;
            margin: 0 0 20px 0;
            background: #fff;
            border-left: 4px solid #dd3d36;
            -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
            box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
            }
            .succWrap{
                padding: 10px;
                margin: 0 0 20px 0;
                background: #fff;
                border-left: 4px solid #5cb85c;
                -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
                box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
            }
        </style>
    </head>
    <body>
  <?php include('includes/header.php');?>
       <?php include('includes/sidebar.php');?>
            <main class="mn-inner">
                <div class="row">
                    <div class="col s12">
                        <div class="page-title"></div>
                    </div>
                    <div class="col s12 m12 l6">
                        <div class="card">
                            <div class="card-content">
                                <div class="row">
                                    <div class="imp_data">
                                    <span class="card-title"><a href="dashboard.php">Dashboard</a>&nbsp;>&nbsp;Employee&nbsp;|&nbsp;Import&nbsp;Data</span>

                                    </div>
                                    <form class="col s12" name="chngpwd" method="post" enctype="multipart/form-data">
                                          <?php if($_GET['error'] == 2 ){?>
                                                <div class="errorWrap">
                                                 <strong>ERROR</strong> : <?php echo htmlentities($error); ?>
                                                </div><?php }
                                                    else if($_GET['success'] == 1){?><div class="succWrap">
                                                    <strong>SUCCESS</strong> : <?php echo htmlentities($msg); ?>
                                                </div>
                                            <?php }?>

                                            <?php if($_GET['errors'] == 3 ){?>
                                                <div class="errorWrap">
                                                 <strong>ERROR</strong> : <?php echo htmlentities($errors); ?>
                                                </div><?php }
                                                    else if($_GET['success'] == 4){?><div class="succWrap">
                                                    <strong>SUCCESS</strong> : <?php echo htmlentities($msg); ?>
                                                </div>
                                            <?php }?>
                                           
                                           
                                        <div class="row">
                                            <div class="input-row">
                                                    <label class="col-md-4 control-label"></label> <input
                                                        type="file" name="file" id="file" accept=".csv">
                                                    <button type="submit" id="submit" name="import"
                                                        class="btn-submit">Import</button>
                                                    <br/>
                                                     <div id="labelError"></div>
                                                </div>
                                                <div id="labelError"></div>
                                            </div>   
                                        </div>
                                    </form>
                                </div>
                            </div>
                         <section>
                                <?php
                                        $sqlSelect = "SELECT * FROM lms_master";
                                        $result = mysqli_query($conn, $sqlSelect);
                                                   
                                        if (mysqli_num_rows($result) > 0) {
                                        ?>
                                        <table id='userTable'>
                                            <thead>
                                                <tr>
                                                    <th>First Name</th>
                                                    <th>EmailId</th>
                                                    <th>Gender</th>
                                                    <th>Dob</th>
                                                    <th>Address</th>
                                                    <th>C_Address</th>
                                                    <th>City</th>
                                                    <th>state</th>
                                                    <th>pincode</th>
                                                    <th>Mobile</th>
                                                    <th>LastStatus</th>
                                                    <th>LastCall</th>
                                                    <th>Remark</th>
                                                    <th>CSV Date</th>
                                                </tr>
                                            </thead>
                                            <?php
                                            while ($row = mysqli_fetch_array($result)) {
                                            ?>
                                            <tbody>
                                                <tr>
                                                    <td><?php  echo $row['FirstName ']; ?></td>
                                                    <td><?php  echo $row['EmailId ']; ?></td>
                                                    <td><?php echo $row['Gender']; ?></td>
                                                    <td><?php  echo $row['Dob']; ?></td>
                                                    <td><?php  echo $row['Address']; ?></td>
                                                    <td><?php  echo $row['C_Address']; ?></td>
                                                    <td><?php  echo $row['City']; ?></td>
                                                    <td><?php  echo $row['state']; ?></td>
                                                    <td><?php  echo $row['pincode']; ?></td>
                                                    <td><?php  echo $row['Mobile']; ?></td>
                                                    <td><?php  echo $row['LastStatus']; ?>
                                                    </td>        
                                                    <td><?php  echo $row['LastCall']; ?></td>
                                                    <td><?php  echo $row['Remark']; ?></td>
                                                    <td><?php  echo $row['Csv_Date']; ?></td>
                                                </tr>
                                             <?php
                                             }
                                             ?>
                                            </tbody>
                                        </table>
                                        <?php } ?>
                            </section> 
                        </div>
                    </div>
                    <!-- start second part right -->
                    <section>
                    </section>
                </div>
            </main>
        </div>
        <div class="left-sidebar-hover"></div>
        <!-- Javascripts -->
        <script src="../assets/plugins/jquery/jquery-2.2.0.min.js"></script>
        <script src="../assets/plugins/materialize/js/materialize.min.js"></script>
        <script src="../assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
        <script src="../assets/plugins/jquery-blockui/jquery.blockui.js"></script>
        <script src="../assets/js/alpha.min.js"></script>
        <script src="../assets/js/pages/form_elements.js"></script>
        <!-- Import CSV File -->
        <script type="text/javascript">
            <script type="text/javascript">
        $(document).ready(
            function() {
            $("#frmCSVImport").on(
            "submit",
            function() {
            $("#response").attr("class", "");
            $("#response").html("");
            var fileType = ".csv";
            var regex = new RegExp("([a-zA-Z0-9\s_\\.\-:])+("
                    + fileType + ")$");
            if (!regex.test($("#file").val().toLowerCase())) {
                $("#response").addClass("error");
                $("#response").addClass("display-block");
                $("#response").html(
                        "Invalid File. Upload : <b>" + fileType
                                + "</b> Files.");
                return false;
            }
            return true;
        });
    });
</script>
        </script>
    </body>
</html>
<?php } ?>


<!-- start csv file
 -->
 <?php 
$connect = mysqli_connect("localhost", "root", "", "testing");
if(isset($_POST["submit"]))
{
 if($_FILES['file']['name'])
 {
  $filename = explode(".", $_FILES['file']['name']);
  if($filename[1] == 'csv')
  {
   $handle = fopen($_FILES['file']['tmp_name'], "r");
   while($data = fgetcsv($handle))
   {
    $item1 = mysqli_real_escape_string($connect, $data[0]); 
                $item2 = mysqli_real_escape_string($connect, $data[1]);
                $query = "INSERT into excel(excel_name, excel_email) values('$item1','$item2')";
                mysqli_query($connect, $query);
   }
   fclose($handle);
   echo "<script>alert('Import done');</script>";
  }
 }
}
?> 
<!DOCTYPE html> 
<html> 
 <head> 
  <title>Webslesson Tutorial</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
 </head> 
 <body> 
  <h3 align="center">How to Import Data from CSV File to Mysql using PHP</h3><br />
  <form method="post" enctype="multipart/form-data">
   <div align="center"> 
    <label>Select CSV File:</label>
    <input type="file" name="file" />
    <br />
    <input type="submit" name="submit" value="Import" class="btn btn-info" />
   </div>
  </form>
 </body> 
</html>

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

12 February, 2019

Node.js Timer

 Programing Coderfunda     February 12, 2019     Nodejs-Hindi, Nodejs-Timer     No comments   

Node.js Timer - Node.js टाइमर

Node.js टाइमर फ़ंक्शन वैश्विक फ़ंक्शन हैं। टाइमर फ़ंक्शन का उपयोग करने के लिए आपको आवश्यकता () फ़ंक्शन का उपयोग करने की आवश्यकता नहीं है। आइए टाइमर फ़ंक्शन की सूची देखें।

टाइमर फ़ंक्शन सेट करें:

     setImmediate (): इसका उपयोग setImmediate को निष्पादित करने के लिए किया जाता है।
     setInterval (): इसका उपयोग समय अंतराल को परिभाषित करने के लिए किया जाता है।
     setTimeout (): () - इसका उपयोग देरी के बाद एक बार कॉलबैक निष्पादित करने के लिए किया जाता है।

टाइमर कार्य साफ़ करें:

     ClearImmediate (तात्कालिक ऑबजेक्ट): इसका उपयोग एक तत्काल ऑबजेक्ट को रोकने के लिए किया जाता है, जैसा कि setImmediate द्वारा बनाया गया है
     ClearInterval (इंटरवलऑब्जेक्ट): इसका उपयोग इंटरवलऑब्जेक्ट को रोकने के लिए किया जाता है, जैसा कि setInterval द्वारा बनाया गया है
     clearTimeout (timeoutObject): यह टाइमआउट ऑबजेक्ट को रोकता है, जैसा कि सेटटाइमआउट द्वारा बनाया गया है

Node.js Timer setInterval() Example

This example will set a time interval of 1000 millisecond and the specified comment will be displayed after every 1000 millisecond until you terminate.

File: timer1.js

    setInterval(function() { 
     console.log("setInterval: Hey! 1 millisecond completed!..");  
    }, 1000);  

  1. var i =0;  
  2. console.log(i);  
  3. setInterval(function(){  
  4. i++;  
  5. console.log(i);  
  6. }, 1000);   
Open Node.js command prompt and run the following code:

Node.js Timer setTimeout() Example

File: timer1.js
  1. setTimeout(function() {   
  2. console.log("setTimeout: Hey! 1000 millisecond completed!..");  
  3. }, 1000);  
Open Node.js command prompt and run the following code:

This example shows time out after every 1000 millisecond without setting a time interval. This example uses the recursion property of a function.
File: timer2.js
  1. var recursive = function () {  
  2.     console.log("Hey! 1000 millisecond completed!..");   
  3.     setTimeout(recursive,1000);  
  4. }  
  5. recursive();   
Open Node.js command prompt and run the following code:

Node.js setInterval(), setTimeout() and clearTimeout()

Let's see an example to use clearTimeout() function.
File: timer3.js
  1. function welcome () {  
  2.   console.log("Welcome to JavaTpoint!");  
  3. }  
  4. var id1 = setTimeout(welcome,1000);  
  5. var id2 = setInterval(welcome,1000);  
  6. clearTimeout(id1);  
  7. //clearInterval(id2);  

Node.js setInterval(), setTimeout() and clearInterval()

Let's see an example to use clearInterval() function.
File: timer3.js
  1. function welcome () {  
  2.   console.log("Welcome to JavaTpoint!");  
  3. }  
  4. var id1 = setTimeout(welcome,1000);  
  5. var id2 = setInterval(welcome,1000);  
  6. //clearTimeout(id1);  
  7. clearInterval(id2); 


 

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Node.js OS

 Programing Coderfunda     February 12, 2019     Nodejs-Hindi, Nodejs-OS     No comments   

Node.js OS

Node.js OS provides some basic operating-system related utility functions. Let's see the list generally used functions or methods.
Index Method Description
1. os.arch() This method is used to fetch the operating system CPU architecture.
2.
os.cpus()
This method is used to fetch an array of objects containing information about each cpu/core installed: model, speed (in MHz), and times (an object containing the number of milliseconds the cpu/core spent in: user, nice, sys, idle, and irq).
3. os.endianness() This method returns the endianness of the cpu. Its possible values are 'BE' for big endian or 'LE' for little endian.
4. os.freemem() This methods returns the amount of free system memory in bytes.
5. os.homedir() This method returns the home directory of the current user.
6.
os.hostname()
This method is used to returns the hostname of the operating system.
7. os.loadavg() This method returns an array containing the 1, 5, and 15 minute load averages. The load average is a time fraction taken by system activity, calculated by the operating system and expressed as a fractional number.
8. os.networkinterfaces() This method returns a list of network interfaces.
9. os.platform() This method returns the operating system platform of the running computer i.e.'darwin', 'win32','freebsd', 'linux', 'sunos' etc.
10. os.release() This method returns the operating system release.
11. os.tmpdir() This method returns the operating system's default directory for temporary files.
12. os.totalmem() This method returns the total amount of system memory in bytes.
13. os.type() This method returns the operating system name. For example 'linux' on linux, 'darwin' on os x and 'windows_nt' on windows.
14. os.uptime() This method returns the system uptime in seconds.
15. os.userinfo([options]) This method returns a subset of the password file entry for the current effective user.

IN - HINDI


Node.js OS कुछ बुनियादी ऑपरेटिंग-सिस्टम संबंधित उपयोगिता फ़ंक्शंस प्रदान करता है। आइए सूची को आमतौर पर उपयोग किए जाने वाले कार्यों या विधियों को देखें।
सूचकांक विधि विवरण
1. os.arch () इस पद्धति का उपयोग ऑपरेटिंग सिस्टम CPU आर्किटेक्चर लाने के लिए किया जाता है।
2।
os.cpus ()
इस विधि का उपयोग उन वस्तुओं की एक सरणी को लाने के लिए किया जाता है जिनमें प्रत्येक cpu / कोर के बारे में जानकारी होती है: मॉडल, गति (मेगाहर्ट्ज में), और समय (मिलीसेकंड की संख्या वाली एक वस्तु जिसमें cpu / कोर का खर्च होता है: उपयोगकर्ता, अच्छा, sys बेकार, और irq)।
3. os.endianness () यह विधि cpu की समाप्ति को लौटाती है। इसके संभावित मूल्य बड़े एंडियन के लिए 'बीई' या छोटे एंडियन के लिए 'एलई' हैं।
4. os.freemem () यह विधि बाइट्स में मुफ्त सिस्टम मेमोरी की मात्रा लौटाती है।
5. os.homedir () यह विधि वर्तमान उपयोगकर्ता की होम डायरेक्टरी लौटाती है।
6।
os.hostname ()
इस पद्धति का उपयोग ऑपरेटिंग सिस्टम के होस्टनाम को वापस करने के लिए किया जाता है।
7. os.loadavg () यह विधि एक सरणी देता है जिसमें 1, 5 और 15 मिनट का लोड औसत होता है। लोड औसत सिस्टम गतिविधि द्वारा लिया गया एक समय का अंश है, जिसे ऑपरेटिंग सिस्टम द्वारा गणना की जाती है और एक भिन्नात्मक संख्या के रूप में व्यक्त किया जाता है।
8. os.networkinterfaces () यह विधि नेटवर्क इंटरफेस की एक सूची लौटाती है।
9. os.platform () यह विधि चल रहे कंप्यूटर के ऑपरेटिंग सिस्टम प्लेटफॉर्म को लौटा देती है यानी 'win32', 'win32', 'freebsd', 'linux', 'sunos' आदि।
10. os.release () यह विधि ऑपरेटिंग सिस्टम रिलीज़ लौटाती है।
11. os.tmpdir () यह विधि अस्थायी फ़ाइलों के लिए ऑपरेटिंग सिस्टम की डिफ़ॉल्ट निर्देशिका लौटाती है।
12. os.totalmem () यह विधि बाइट्स में सिस्टम मेमोरी की कुल राशि लौटाती है।
13. os.type () यह विधि ऑपरेटिंग सिस्टम नाम लौटाती है। उदाहरण के लिए 'linux' पर linux, os x पर 'darwin' और windows पर 'windows_nt'।
14. os.uptime () यह विधि सेकंड में सिस्टम अपटाइम लौटाती है।
15. os.userinfo ([विकल्प]) यह विधि मौजूदा प्रभावी उपयोगकर्ता के लिए पासवर्ड फ़ाइल प्रविष्टि का सबसेट लौटाती है।

Node.js OS उदाहरण 1

इस उदाहरण में, हम कुछ बुनियादी कार्यों को शामिल कर रहे हैं। निम्नलिखित कोड वाले os_example1.js नाम की फ़ाइल बनाएँ:

फ़ाइल: os_example1.js

     const os = आवश्यकता ('os');
     कंसोल.लॉग ("os.freemem (): \ n", os.freemem ());
     कंसोल.लॉग ("os.homedir (): \ n", os.homedir ());
     कंसोल.लॉग ("os.hostname (): \ n", os.hostname ());
     कंसोल.लॉग ("os.endianness (): \ n", os.endianness ());
     कंसोल.लॉग ("os.loadavg (): \ n", os.loadavg ());
     कंसोल.लॉग ("os.platform (): \ n", os.platform ());
     कंसोल.लॉग ("os.release (): \ n", os.release ());
     कंसोल.लॉग ("os.tmpdir (): \ n", os.tmpdir ());
     कंसोल.लॉग ("os.totalmem (): \ n", os.totalmem ());
     कंसोल.लॉग ("os.type (): \ n", os.type ());
     कंसोल.लॉग ("os.uptime (): \ n", os.uptime ());

or English 

Node.js OS Example 1

In this example, we are including some basic functions. Create a file named os_example1.js having the following code:
File: os_example1.js
  1. const os=require('os');  
  2. console.log("os.freemem(): \n",os.freemem());  
  3. console.log("os.homedir(): \n",os.homedir());  
  4. console.log("os.hostname(): \n",os.hostname());  
  5. console.log("os.endianness(): \n",os.endianness());  
  6. console.log("os.loadavg(): \n",os.loadavg());  
  7. console.log("os.platform(): \n",os.platform());  
  8. console.log("os.release(): \n",os.release());  
  9. console.log("os.tmpdir(): \n",os.tmpdir());  
  10. console.log("os.totalmem(): \n",os.totalmem());  
  11. console.log("os.type(): \n",os.type());  
  12. console.log("os.uptime(): \n",os.uptime());  
Open Node.js command prompt and run the following code:
  1. node os_example1.js 
 Node.js OS उदाहरण 2

इस उदाहरण में, हम शेष कार्यों को शामिल कर रहे हैं। निम्नलिखित कोड वाले os_example2.js नामक फ़ाइल बनाएँ:

फ़ाइल: os_example2.js

     const os = आवश्यकता ('os');
     कंसोल.लॉग ("os.cpus (): \ n", os.cpus ());
     कंसोल.लॉग ("os.arch (): \ n", os.arch ());
     कंसोल.लॉग ("os.networkInterfaces (): \ n", os.networkInterfaces ());

Node.js कमांड प्रॉम्प्ट खोलें और निम्न कोड चलाएँ:

     नोड os_example2.js


Node.js OS Example 2

In this example, we are including remaining functions. Create a file named os_example2.js having the following code:

File: os_example2.js

    const os=require('os'); 
    console.log("os.cpus(): \n",os.cpus()); 
    console.log("os.arch(): \n",os.arch()); 
    console.log("os.networkInterfaces(): \n",os.networkInterfaces());  

Open Node.js command prompt and run the following code:

    node os_example2.js  


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Meta

Popular Posts

  • Write API Integrations in Laravel and PHP Projects with Saloon
    Write API Integrations in Laravel and PHP Projects with Saloon Saloon  is a Laravel/PHP package that allows you to write your API integratio...
  • Features CodeIgniter
    Features CodeIgniter There is a great demand for the CodeIgniter framework in PHP developers because of its features and multiple advan...
  • Laravel Breeze with PrimeVue v4
    This is an follow up to my previous post about a "starter kit" I created with Laravel and PrimeVue components. The project has b...
  • Fast Excel Package for Laravel
      Fast Excel is a Laravel package for importing and exporting spreadsheets. It provides an elegant wrapper around Spout —a PHP package to ...
  • Send message via CANBus
    After some years developing for mobile devices, I've started developing for embedded devices, and I'm finding a new problem now. Th...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda