Reading from and Writing to the File System in Node.js

Posted by admin at March 20, 2020

Reading from files is done via the core fs module. There are two sets of reading methods: asynchronous (recommended) and synchronous. In most cases, developers should use async methods, such as fs.readFile because this method won’t block the event loop:const fs = require(‘fs’) const path = require(‘path’) fs.readFile(path.join(__dirname, ‘/data/customers.csv’), {encoding: ‘utf-8’}, function (error, data) { if (error) return console.error(error) […]

Continue

require and module.exports

Posted by admin at

Node provides a built-in module mechanism which works with the require() method and the module.exports global object. To demonstrate how require and module.exports work, let’s say we have two files account-service.js and utility.js. The utility.js has some generic methods and objects which we use in many projects and applications. In this example, we will import those generic methods into account-service.js. Here’s the code of utility.js in which […]

Continue

Launching Node Code from a file

Posted by admin at

This is the most common use case because it allows you to save long Node programs and run them. To run a Node.js script from a file, simply type node filename. For example, to launch code from a program.js file which is located in a current folder, simply execute node program.js The file must be in […]

Continue

Node.js Console (REPL)

Posted by admin at

Like most platforms/languages (e.g., Java, Python, Ruby, and PHP), Node.js comes with a virtual environment called Read-Evaluate-Print Loop (REPL). Using REPL (a.k.a. Node console), we can execute pretty much any Node.js/JavaScript code. It is even possible to include modules and work with the file system! To start Node REPL, run the following command in your […]

Continue

ES6: Compare Scopes of the var and let Keywords

Posted by admin at March 3, 2020

When you declare a variable with the var keyword, it is declared globally, or locally if declared inside a function. The let keyword behaves similarly, but with some extra features. When you declare a variable with the let keyword inside a block, statement, or expression, its scope is limited to that block, statement, or expression. For example: With the var keyword, i is declared globally. […]

Continue

ES6: Explore Differences Between the var,let and const Keywords

Posted by admin at

One of the biggest problems with declaring variables with the var keyword is that you can overwrite variable declarations without an error. As you can see in the code above, the camper variable is originally declared as James and then overridden to be David. In a small application, you might not run into this type of problem, but when your code becomes […]

Continue

Node js Introduction

Posted by admin at January 28, 2020

Why Node.js? Let’s start by taking a look at why Node.js is one of the fastest growing web platforms out there. Node.js provides you with the following benefits: Develop faster due to the vast number of modules and reusable code from npm Make fewer mistakes and be more productive (One language across the stack) Delight […]

Continue

JavaScript array functions

Posted by admin at January 15, 2020

Arrays provide a lot of methods. here some of important methods that are used to handle the array and manipulate the array Arrays functions push()pop()shift()unshift()findIndex()sort(ASC)sort(DES)reverse() // display the array data function showArr() { if (arrays.length { return n == num; }); console.log(ind); if (ind === -1) { document.getElementById(“result”).innerHTML = num + ” Number not found”; […]

Continue

JavaScript Arrow Function

Posted by admin at

Arrow functions – also called “fat arrow” functions, from CoffeeScript are a more concise syntax for writing function expressions. They utilize a new token, =>, that looks like a fat arrow. Arrow functions are anonymous and change the way this binds in functions. Arrow Function Syntax Arrow functions have a single overarching structure, and then an number of […]

Continue

Bootstrap Billing form

Posted by admin at January 14, 2020

Bootstrap provides three types of form layouts: Vertical form (this is default) Horizontal form Inline form Standard rules for all three form layouts: Wrap labels and form controls in <div class=”form-group”> (needed for optimum spacing) Add class .form-control to all textual <input>, <textarea>, and <select> elements Billing and Payment Details Full Name Address CountryChooseIndiaPakistanAmericaIraq StateChooseUttar PradeshBiharDelhiMaharastra State Shopping address is same as Billing […]

Continue