Saturday, December 19, 2020

NodeJs, NPM, AND SEMANTIC VERSIONING

1. Node Js

  • What is Node Js?
                    Node.js is an open source server environment and Node.js is free. Node.js  runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.). Node.js also uses JavaScript on the server.

        >>Node js uses asynchronous programming!
A common task for a web server can be to open a file on the server and return the content to the client.

        Here is how PHP or ASP handles a file request:

  1. Sends the task to the computer's file system.
  2. Waits while the file system opens and reads the file.
  3. Returns the content to the client.
  4. Ready to handle the next request.

         Here is how Node.js handles a file request:

  1. Sends the task to the computer's file system.
  2. Ready to handle the next request.
  3. When the file system has opened and read the file, the server returns the content to the client.

Node.js eliminates the waiting, and simply continues with the next request. Node.js runs single-threaded, non-blocking, asynchronously programming, which is very memory efficient. Node.js can Do following task:

  • 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 our database
Developer can implement Node js in their projects by downloading the latest stable version from it's official site nodejs.org.


2. NPM
    


NPM is a package manager for Node.js packages, or modules if we like. www.npmjs.com hosts thousands of free packages to download and use. The NPM program is installed on our computer when we install Node.js NPM is already ready to run on our computer! npm is included as a recommended feature in the Node.js installer.

npm can manage packages that are local dependencies of a particular project, as well as globally-installed JavaScript tools.

There are a number of open-source alternatives to npm for installing modular JavaScript, including ied , pnpm, npmd, and Yarn, the last of which was released by Facebook also in October 2016.


3.Semantic
To keep the JavaScript ecosystem healthy, reliable, and secure, every time we make significant updates to an npm package we own, we recommend publishing a new version of the package with an updated version number in the package.jsonfilethat follows the semantic versioning specifications.

Semantic Versioning is a 3-component number in the format of a.b.c, where :

  • a stands for a major version.
  • b stands for a minor version.
  • c stands for a patch.
So, SemVer(Semantic Version) is of the form Major.Minor.Patch.

Working : The goal of semantic versioning  was to bring some sanity to the management of rapidly moving software release targets. As discussed above, 3 numbers i.e, Major, Minor and Patch are required to identify a software version. For example, if we take version 5.12.2, then it has a major version of 5, a minor version of 12 and a patch version of 2. Below given are the scenarios when we should bump the value of a, b and c.

  • Bump the value of a when breaking the existing API.
  • Bump the value of when implementing new features in a backward-compatible way.
  • Bump the value of c when fixing bugs.
4. Package.json
The package.json file is the heart of Node.js system. It is the manifest file of any Node.js project and contains the metadata of the project. The package.json file is the essential part to understand, learn and work with the Node.js. It is the first step to learn about development in Node.js.

What does package.json file consist of?

It consists of two properties:

Identifying metadata properties

Functional metadata properties

It basically consist of the properties to identify the module/project such as the name of the project, current version of the module, license, author of the project, description about the project etc.

As the name suggests, it consists of the functional values/properties of the project/module such as the entry/starting point of the module, dependencies in project, scripts being used, repository links of Node project etc.

 Creating a package.json file:A package.json file can be created in two ways:

1. Using npm init : Running this command, system expects user to fill the vital information required as discussed above. It provides users with default values which are editable by the user.Syntax:

                                                  npm init

2. Writing directly to file : One can directly write into file with all the required information and can include it in the Node project.



Saturday, December 12, 2020

THE BASICS ON JavaScript

 

DECLARATION AND INITIALIZATION

As we discussed introductions and some main important of JavaScript in programming word for beginners. Now in second lecture we are discussing about some new points like basics in JavaScript , declaration on JavaScript etc.

Before we use a variable in a JavaScript program, we must declare it. Variables are declared with the var keyword. For example:

                                                             var age;

                                                               var name;

And also we can use only keyword for more variables as:

                                                              var age, name;

 

Storing a value in a variable is called variable initialization. We can do variable initialization at the time of variable creation or at a later point in time when we need that variable.

For instance, we might create a variable named money and assign the value 24 to it later. For another variable, we can assign a value at the time of initialization as follows:

                     var name = "Mahesh Prashad Joshi";
                var age;
                     age = 24;

 

We should remember that the var keyword only for declaration or initialization, once for the life of any variable name in a document. We should not re-declare same variable twice.

If we are declaring the variable in JavaScript we should use the variables properly. For example:






These declarations will so the result as:



If we interchange the declaration steps in another way like:


<script> 

        alert(x);

        x="Mahesh Prashad Joshi"

        var x;

    </script>

 

This result as:



 

Reference Error and Undefined Basically we may face two kinds of errors Reference while declaration of the variable. Reference error arises if we have not declared a variable but we are trying to use it. Undefined is the case when we try to use a variable that we have declared but have not assigned any value to it.

<script>

        document.writeln(x);

    </script>

 This shows the reference error while run in the browser as shown as below:

                  

And lets see another error:



This declaration creates the undefined type of error in JavaScript. And shows the result as:

 

 



 

Data Types in JavaScript:

Basically JS has 8 basic data types:

SN

Data Type

Work As

1

number

variable with number data type stores integer or floating-point values.

2

bigint

integer numbers(of arbitrary length).

3

string

For string values.

4

boolean

True/false.

5

null

Unknown values

6

undefined

Unassigned value.

7

object

Complex data structures.

8

symbol

Unique Identifier.

 

And the three data types string, number, boolean are primitive data types. Here is the method to declare of these data type in programming language:



From Above program we can conclude the result as:



Thursday, December 3, 2020

JavaScript AND IT'S IMPORTANCE FOR NEW DEVELOPER

JavaScript is a programming language used primarily by Web browsers to create a dynamic and interactive experience for the user. The earliest incarnations of JavaScript were developed in the late 1990s by Brendan Eich for the Netscape Navigator Web browser. For the first time, JavaScript enabled animation, adaptive content and form validation on the page.

 

JavaScript did not become standardized and widely adopted until 1999. Even after standardization, browser compatibility remained an issue for over a decade and for many years; JavaScript only functioned on a limited number of browsers. Microsoft's Internet Explorer, the largest browser base, did not support JavaScript until much later. As I know JavaScript and Java are very much unrelated. Java is a very complex programming language whereas JavaScript is only a scripting language. The syntax of JavaScript is mostly influenced by the programming language C.

If we discuss about important of JavaScript:

The language JavaScript as a web technology can be determined from the fact that it is currently used by 94.5% of all websites. As a client-side programming language, JavaScript helps web developers to make web pages dynamic and interactive by implementing custom client-side scripts.

At the same time, we (developers) can also use cross-platform runtime engines like Node.js to write server-side code in JavaScript. They can even combine JavaScript, HTML5 etc to create web pages because they look good across browsers and devices.

 

How to Run JavaScript?

As above mentioned, being a scripting language, JavaScript cannot run on its own. In fact, the browser is responsible for running JavaScript code. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it is up to the browser to execute it. The main advantage of JavaScript is that all modern web browsers support JavaScript. So, we do not have to worry about whether we site visitor uses Internet Explorer, Google Chrome, Firefox or any other browser. Also, JavaScript runs on any operating system including Windows, Linux or Mac.

To start with, we need a text editor to write our code and a browser to display the web pages we develop. We can use a text editor of our choice including Notepad++, Visual Studio Code, Sublime Text, Atom or any other text editor we are comfortable with. We can use any web browser including Google Chrome, Firefox, Microsoft Edge, Internet Explorer etc.

 

How Can we write Simple JavaScript Program?

We should place all our JavaScript code within <script> tags (<script> and </script>) if we are keeping our JavaScript code within the HTML document itself. This helps our browser distinguish our JavaScript code from the rest of the code. We have to use the type attribute within the <script> tag and set its value to text/javascript like this:

                                                        <script type="text/javascript">

Here is the Simple Program to print Mahesh Prashad Joshi :

<html>

<head>

            <title>This is the first code</title>

            <script type="text/javascript">

                        alert("Mahesh Prashad Joshi");

            </script>

</head>

<body>

</body>

</html>

 

As the end we can concluded that JavaScript is a client-side scripting language developed by Brendan Eich. JavaScript can be run on any operating systems and almost all web browsers. We need a text editor to write JavaScript code and a browser to display our web page.