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.



0 comments:

Post a Comment