edit

JS Fundamentals

vers 7 updated on 18 Oct 2021 by ( bismay/ bismay)

Introduction to Nodejs

Node.js and Angular 5 are popular in modern days. These two technologies are important for building a Mean Stack Application. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications.

Why Nodejs ?

As Node.js is a asynchronous programming we don’t need to wait for one request to complete fully, it’s simply take the next request so there is no waiting time and that’s is the best part of the Node.js. Node.js is very memory efficient because of it’s features.

Features of Node.js

  • Following are some of the important features that make Node.js the first choice of software architects.
  • Asynchronous and Event Driven All APIs of Node.js library are asynchronous, that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.
  • Very Fast Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution.
  • Single Threaded but Highly Scalable Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
  • No Buffering Node.js applications never buffer any data. These applications simply output the data in chunks.

1. Javascript Basics https://www.w3schools.com/js/

  • Core Javascript
    • Iterations - Loops offer a quick and easy way to do something repeatedly
    • Variables - Variables are containers that store values.
      • Comments - Comments are snippets of text that can be added along with code.
      • Operators - An operator is a mathematical symbol that produces a result based on two values (or variables).
      • Conditionals - Conditionals are code structures used to test if an expression returns true or not
      • Events - Real interactivity on a website requires event handlers. These are code structures that listen for activity in the browser, and run code in response.
    • Array - JavaScript arrays are used to store multiple values in a single variable.
    • String - JavaScript strings are used for storing and manipulating text.
    • Functions - Functions are a way of packaging functionality that you wish to reuse.
    • Date and Time - creates a new date object with the current date and time:
  • Error and Exceptions - Errors are thrown by the engine, and exceptions are thrown by the developer. All exceptions are simply objects.
  • RegEx - Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects.

2. NodeJS Basics https://www.w3schools.com/nodejs/

Basics

  • NPM - npm is two things: first and foremost, it is an online repository for the publishing of open-source Node.js projects; second, it is a command-line utility for interacting with said repository that aids in package installation, version management, and dependency management
  • PM2 - PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
  • Require - Node.js follows the CommonJS module system, and the builtin require function is the easiest way to include modules that exist in separate files.
  • module.exports - to define dependencies and modules

Steps to include functions from other Files

  • Creating a Module - Modules are created in Node.js are JavaScript files. Every time a new file with .js extension is created, it becomes a module.
  • Exporting a Module - Filename: func.js
  • Importing a Module - We need to import the module to use the functions defined in the imported module in another file. The result returned by require( ) is stored in a variable which is used to invoke the functions using the dot notation.

Functionalities and Concepts

  • FileSystem - The Node.js file system module allows you to work with the file system on your computer.
  • Events - Every action on a computer is an event. Like when a connection is made or a file is opened.
  • Servers - functions as an API, and uses express framework.
  • Clients - is just a node-static app that serves static javascript/html files.

3. NodeJS Frameworks

  • Express - Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications.
  • Restify (Restify, Restify-Errors) - A Node.js web service framework optimized for building semantically correct RESTful web services ready for production use at scale.

4. NodeJS Libraries

Libraries

  • Lodash - It is used to simplify your work of managing and editing objects and arrays by providing lots of utility methods to do so.
  • MomentJS - A JavaScript date library for parsing, validating, manipulating, and formatting dates.
  • MD5 - a JavaScript function for hashing messages with MD5.
  • SHA512 - hash functions for JavaScript supports UTF-8 encoding.
  • Axios - Promise based HTTP client for the browser and node.js
  • bunyan logger - Bunyan is a simple and fast JSON logging library for node.js services
  • nodemailer - The Nodemailer module makes it easy to send emails from your computer.
  • Body Parser - Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
  • Nodemailer - Sends an email using nodejs
  • Async - Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript
  • Validator - A library of string validators and sanitizers.
  • Lodash

Drivers

  • ioredis - A robust, performance-focused and full-featured Redis client for Node.js.
  • MySQL - Node.js can be used in database applications.
  • MongoDB- MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time
  • Sequelize - Sequelize is a powerful library in Javascript that makes it easy to manage a SQL database.
  • Mongoose - Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.

5. NodeJS Security Concepts

  • Middelware - Middleware functions are functions that have access to the request object (req), the response object (res), and the next function in the application’s request-response cycle
  • JWT - JWT specifies a compact and self-contained method for communicating information as a JSON object between two parties. Because it is signed, this information can be checked and trusted. JWTs can be signed using a secret (using the HMAC algorithm) or an RSA or ECDSA public/private key combination.
  • OAuth2 - is the industry-standard protocol for authorization, enabling third-party applications to obtain limited access to an HTTP service, either on behalf of a resource owner or by allowing the third-party application to obtain access on it's own behalf.