Top Stories

Ankaj Gupta
December 30, 2018
Require module in Node.js | Nodejs

Require in node.js

The require() function allows you to include modules into your programs. You can import built-in node.js modules, community-based modules(node_modules) and local modules.

The function require() returns an object, which references the value of module.exports for a given file, when the require is invoked, a sequences of tasks are happened:

Require will look for file/directory in the following order:

  • Built-in module Node.js modules (like: fs module), show in Example-1

  • Modules in node_modules folder.

    • If the module name has a ./, / or ../, it will look for the directory in the given path. It matches the extensions: *.js, *.json and *.node.

Note : The require is a function that takes one argument called path, Node.js.

How to Use require() function

  • Importing a local Coustom module or module

const myLocalModule = require('./path/myLocalModules');

  • Importing a JSON file

const jsonData = require('./path/jsonFile.json');

  • Importing a module from Node.js built-in modules or node_modules.

const crypto = require('crypto');

 ➤ Example 1: myMod.js

const fs = require('fs');
  fs.readFile('./myfile.txt', 'utf-8', (err, data) => 
  {
    if(err)
     { throw err; }
    console.log('data: ', data);
  });

In Example-1 the path is "./myfile".

Node.js
Read more
Ankaj Gupta
December 27, 2018
What is module in Node.js?

A set of functions you include in your node.js application, that is a module. Modules can be either be single files or directories containing one or more file. Let's see in detail

Node.js Modules

Consider modules to be the same as Java-Script libraries. A module encapsulates code into a single unit of code.

Whenever you create any type of functions / objects in node.js and you reuse the these functions/objects , then these process you can called module.

  • For example : Mathematical calculation, Fatch the data from database and any type of task you want to perform , then you need create a module.

Type of modules in node.js.

  • Built-in Modules

  • Custom modules (User defined modules).

Note : When ever if we don’t create any Node.js modules ourselves, then we already have modules at our disposal because the Node.js environment provides so many built-in modules for us.

# roles inside of Node.js

The Module has two-main roles inside of Node.js.

  • The module’s First, it provides a foundation for all Node.js modules to build off. Each file is given a new example of this base module on load, which persists even after the file has run. This's why we are able attach properties to "module.exports" and return them later as needed.

  • The module’s second big job is to handle Node.js module loading mechanism. The require() function that we use is actually an abstraction over module.require, which is itself just a simple wrapper around Module._load. This load method handles the actual loading of each file, and where we’ll begin our journey.

1. Built-in Modules

Node.js has a set of built-in modules which you can use without any further installation.Built-in Modules is provided by the system.

  • Built-in modules is also called Core modules.

  • The Built-in modules are defined within Node.js source and are located in the "lib/" folder.

  • The Built-in modules has several modules compiled into the binary and load automatically when Node.js process starts.

  • Built-in modules are always preferentially loaded if their identifier is passed to require(). For example, require('http') will always return the built in HTTP module, even if there is a file by that name.

=> How to Include Built-in Modules

The module is implemented in the require('module') function, by using require() function you include the Built-in module in node.js

 ➤ Example: Include the "http" built-in module

var http = require('http');

Now your node.js application has included and access to the HTTP module, and is able to create a server:

 ➤ Example: Include and Use http Module

var http = require('http');
http.createServer(function (req, res)
  {
     res.writeHead(200, {'Content-Type': 'text/plan'});
     res.end('Hello Node.js!');
  }).listen(8080);

2. Custom modules

Custom modules is created by user, by using exports keyword and use it in your application.

  • It is also called User defined modules, File modules or Own modules.

  • With the help of the exports keyword to make properties and methods available outside the module file.

=> How to create your Custom modules

  You use exports keyword to create the Custom module in node.js

 ➤ Example: mymodule-file.js

    Create a module that returns the value of add() function

exports.add= function(x,y)
  {
    return x + y ;
  }

=> How to Include Custom modules

require('module') function also used to include Custom module in node.js

 ➤ Example: index-file.js

    Use the module "mymodule-file.js" in a Node.js file

var http=require('http');
var module_object= require('./mymodule-file');//Here included mymodule-file.js
http.createServer(function (req,res){
  res.writeHead(200, {'Content-Type': 'text/plan'});
  res.write("mymodule-file output is : "+module_object.add(25,60).toString());
  res.end();
}).listen(8080);
Node.js
Read more
Ankaj Gupta
December 25, 2018
Node.js console based example

How To Write and Run Your First Program in Node.js

Step 1: Create a new Node.js file and save named"console_first.js"

 ➤ File Name: console_first.js

console.log('Hello Node.js');

Step 2: Open Command prompt / Node.js command prompt interface, on your computer depends on the operating system. For Windows users : Click on the start button and look for "Command Prompt" or simply write "cmd" in the search field.

tutorials.coderwebsite.com tutorials.coderwebsite.com

Now command prompt is open set your path, Here we have save "console_first.js" file on the desktop.

 ➤ Note: run the following code, For go to desktop

cd desktop

Step 3: After setting the path , run the following code

 ➤ Note: For display output

node console_first.js

This code you can run on the command prompt, as well as Node.js command prompt. You can show below output photos.

a.) Command-prompt output :

tutorials.coderwebsite.com

b.) Node.js command-prompt output :

tutorials.coderwebsite.com

Here you called, console.log() function and display message on console.

Node.js
Read more
Ankaj Gupta
December 25, 2018
How node.js is different from PHP and ASP ?

Node.js is different from PHP and ASP

How Handle request Node.js

  • Node.js send request to the server.

  • Node.js pick new request and do not wait till the request get completed.

  • In node.js once the first request get completed it server back data to the client.

  • It eliminates the waiting, and simply continues with the next request.

How handle request PHP and ASP

  • PHP or ASP send request to the server.

  • PHP or ASP wait till the request get completed.

  • PHP or ASP return the data when request get completed.

  • PHP or ASP send another new request.

Node.js web development and designing
Read more
Ankaj Gupta
December 22, 2018
What are the special features of Node.js

Features of Node.js

There are following some important features of node.js , that make Node.js the first choice of software architects.

1. Very Fast

  • Node.js is built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution, because of its non-blocking paradigm.

2. No Buffering

  • Node.js applications never buffer any data. These applications simply output the data in chunks, Node.js cuts down the overall processing time while uploading audio and video files.

3. Huge number of libraries

  • npm(Node Package Manager) with its simple structure helped the ecosystem of node.js proliferate and now the npm registry hosts almost 500.000 open source packages you can freely use.

4. Event Driven and Asynchronous

  • All APIs of Node.js library are asynchronous non-blocking, So a Node.js based server never waits for an API to return data. The server moves to the next API(Application Programming Interface) after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.

5. Single threaded

  • Node.js follows a single threaded model with event looping.

6. Highly Scalable

  • Node.js is highly scalable because event mechanism helps the server to respond in a non-blocking way.

7. License

  • Node.js is released under the MIT(Massachusetts Institute of Technology) license.

8. Open source

  • Node.js has cross-platform, open source community which has produced many excellent modules to add additional capabilities to Node.js applications.

Node.js
Read more
Ankaj Gupta
December 21, 2018
What is Node.js | nodejs ?

Introduction of Node.js

Node.js (Node) is an open source, cross-platform runtime environment for developing server-side and networking applications.It allows you to run JavaScript on the server-side.

Node.js tutorials

Node.js is a JavaScript runtime built on Chrome's JavaScript V8 engine for easily building fast, scalable network applications.

Node.js is intended to run on a dedicated HTTP(HyperText Transfer Protocol) server and to employ a single thread with one process at a time.

Note : Node.js is written in JavaScript and It is runs on various platforms like: Microsoft Windows, Linux, Unix and Mac OS X, etc.

History

Node.js was developed by Ryan Dahl in 2009, Node.js is a JavaScript runtime built on Chrome's JavaScript V8 engine.

Advantages of Node.js

  • Node.js can generate dynamic page content, It can create, open, delete, read, write, and close files on the server.

  • Node.js applications are event-based and run asynchronously.Node.js Code built on the Node platform does not follow the traditional model of receive, process, send, wait, receive.

  • Node.js uses an event-driven, according to its creator Ryan Dahl, is that it does not block input/output (I/O) model.

  • Node.js makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

  • Node.js is also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.

  • Node is useful for developing applications that require a persistent connection from the browser to the server and is often used for real-time applications such as: news, chat, feeds and web push notifications etc...

Node.js
Read more
Ankaj Gupta
December 16, 2018
What is C Programming Language

The C Language is developed for creating system applications that direct interacts to the hardware devices such as kernels and device drivers etc...

Introduction of C Language

C is a general-purpose high-level programming language. C is a successor of Basic Combined Programming Language (CPL) called B language, developed in the 1960s at Cambridge University. It was developed for the Unix operating system.

c language

B was further modified by Dennis Ritchie in 1972 at (AT&T) Bell Laboratories in Murray Hill to develop the UNIX Operating System. This new language was called C language.

C language is also called mother language of all programming language. It is used for develop system software and Operating System and all other programming languages were derived directly or indirectly from C programming concepts.

It is also known as:
  • Mother language

  • Procedure-oriented and General purpose programming language

  • C is a simple and structure oriented programming

  • C is a High level programming language

#Procedural :Procedural means, C program is a set of functions, each function performs a specific task, In the C program, functions are called in sequence to make the program works as designed.

#General-purpose :It means C language is designed for developing software that applies in a wide range of application domains, Where we use C Language is mainly used for : Design Operating system, Design Language Compiler, Design Database Language, Interpreters Utilities ,Network Drivers Assemblers etc...

c language
Read more
Ankaj Gupta
December 15, 2018
What are the applications of C programming?

Application of C Language


Application of C Programming are listed below, Let's see:

  • C programming language can be used to design Operating System,computer applicationsand Network Devices   etc...

  • C Language is also used for Develop Desktop application and system software.

  • C language can be used to design the compilers

  • Almost every Device Drivers is written in C programming

  • It is used for developing verification software, test code, simulators etc... for various applications and hardware products.

  • It is used to develop application software like database and spread sheets etc...

  • One of the most popular database management systems is written in C programming language.

  • c language
  • Both Unix and Linux were written in C , In fact, C was invented for the sole purpose of writing a cross platform version of Unix.

  • c language
  • MS Office was developed using assembler, then development moved to C,  later, when C++ arose, everything new was done using C++ language
  • Major part of Web browser is written in C Language

c language
Read more
Ankaj Gupta
December 04, 2018
What is Cryptography?

Introduction Of Cryptography

Cryptography is a means for implementing some security mechanisms. The term of 'Cryptography' is derived from two Greek words, namely crypto and graphy. In greek language crypto means secret and graphy means writing.

  • Cryptography is the science of secret writing that provides various techniques to protect information that is an unreadable format. This unreadable format only by the intended recipients.

  • It is the science of converting a message into a code from that hides the information contained in the message. We encrypt a message before its transmission so that an eavesdropped may not get the information contained in the message.

   Plaintext : The original unencrypted message is called plaintext

   Ciphertext : The encryption message is called ciphertext.

# Cryptography technique and protocols:

Cryptography techniques and protocols are used in a wide range of application such as secure electronic transactions, se audio/video broadcasting and se video conferences.

  • In secure electronic transactions, cryptography techniques are used to protect E-mail messages, Credit-card information and other sensitive information.

  • In secure audio/video broadcasting the service provider sends the requested audio/video data to subscribers in a secure way. Only the authorized subscribers are allowed to views the multimedia data.

  • It is used in video conferences to allow multi-party communication, where one user speaks and the remaining users view the communicated data is a secure way.

  • These secure application are heavily dependent on various cryptography services namely confidentiality, authentication and data integrity.

Based on these cryptography servic, the cryptography technique and protocols are classified into 4-main regions and are as follows :

  1. Symmetric Encryption.

  2. Asymmetric Encryption.

  3. Data integrity Techniques.

  4. Authentication Protocols.

1.) Symmetric Encryption : Symmetric encryption is an application technique is which identical cryptography key is used for both encrypting and decrypting the information. Tnis key in practice must be secret between the sender and the receiver to maintain the secrecy of the information.

2.) Asymmetric Encryption : Asymmetric encryption is an encryption technique where two keys are used as a pair. Among these two keys, one key is used for encryption and the other key is used for decryption of information. In the pair of keys, if the sender uses any one key to encrypt a message, the receiver should use another key to decrypt the message.

3.) Data integrity Techniques : These techniques are used to protect information from alteration during the transmission. Data integrity techniques assure to maintain the accuracy and consistency of information over its entire life cycle.

4.) Authentication Protocols : These are designed based on the use of cryptographic techniques to authenticate the identity of the sender. These protocols allow only the valid users to access the resources located on a server.

Cryptography & Network Security
Read more
Ankaj Gupta
November 30, 2018
-> Digital Marketing, Web Development and Go Programming 100% off [ LIMITED_TIME_FREE ]
Coupons Udemy Coupon
Read more
Ankaj Gupta
September 27, 2018
100% Off Udemy Coupons
Coupons Udemy Coupon
Read more
Ankaj Gupta
September 23, 2018
Download free IDE softwares

Software Link
Read more
Ankaj Gupta
September 18, 2018
Install PHP






Software Link
Read more

Discover more amazing content below