edit

JS Advanced

vers 5 updated on 18 Oct 2021 by ( dikshita.juikar/ dikshita.juikar)

Node js Introduction:

Node.js is a server-side platform built on Google Chrome's JavaScript Engine.Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux. Node.js also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent.

Features of Node js:

  • Node.js is really fast: Having been built on Google Chrome's V8 JavaScript engine, its library is extremely fast for code execution.
  • Node Package Manager (NPM): Node Package Manager has more than 50,000 bundles, so whatever functionality is required for an application can be easily imported from NPM.
  • Node.js uses asynchronous programming: All APIs of Node.js library are asynchronous (i.e., non-blocking), so a Node.js-based server does not wait for the API to return data. The server calls the API, and in the event that no data is returned, the server moves to the next API the Events module of Node.js helps the server get a response from the previous API call. This also helps with the speed of Node.js.
  • No buffering: Node.js dramatically reduces the processing time while uploading audio and video files. Node.js applications never buffer data and simply output the data in chunks.
  • Single-threaded: Node.js makes use of a single-threaded model with event looping. As a result, it can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
  • Highly scalable: Node.js server responds in a non-blocking way, making it highly scalable in contrast with traditional servers, which create limited threads to handle requests.

Important parts of Node js:

  • Modules: Modules are like JavaScript libraries that can be used in a Node.js application to include a set of functions. In order to include a module in a Node.js application, use the require( ) function with the parenthesis containing the name of the module. for eg(http, fs).
  • Console: The console is a module that provides a method for debugging that is similar to the basic JavaScript console provided by internet browsers. It prints messages to stdout and stderr.
  • Cluster: Node.js is built-on on the concept of single-threaded programming. Cluster is a module that allows multi-threading by creating child processes that share the same server port and run simultaneously.
  • Global: Global objects in Node.js are available in all modules. These objects are functions, modules, strings, etc
  • Error Handling: Node.js applications experience four types of errors. Errors in Node.js are handled through exceptions.
    • Standard Javascript errors: syntax errors, type error etc.
    • System errors: File does not exist
    • User specific errors: Errors specified by user in the console
    • Asseration errors: Special type of error that occurs in case of logic violation
  • Streaming: Streams are the objects that let you read data or write data continuously. There are four types of streams:
    • Readable: These are the types of streams from which data can be read
    • Writable: These are the types of streams to which data can be written
    • Duplex: These are both readable and writable streams
    • Transform: Streams that can manipulate the data while it is being read or written
  • Buffer: Buffer is a module that allows the handling of streams that contain only binary data.
  • Domain: The domain module intercepts errors that remain unhandled. Two methods are used for intercepting these errors:
    • Internal Binding: Error emitter executes its code inside the run method
    • External Binding: Error emitter is explicitly added to a domain via its add method
  • DNS: DNS module is used to connect to a DNS server. DNS module is also used for performing name resolution without a network communication
  • Debugger: Node.js includes a debugging utility that can be accessed by a built-in debugging client. Node.js debugger is not feature-packed but supports the simple inspection of code. The debugger can be used in the terminal by using the 'inspect' keyword before the name of the JavaScript file.

What is an API?(https://www.mulesoft.com/resources/api/what-is-an-api)

An application programming interface, or API, enables companies to open up their applications’ data and functionality to external third-party developers, business partners, and internal departments within their companies. This allows services and products to communicate with each other and leverage each other’s data and functionality through a documented interface. Developers don't need to know how an API is implemented; they simply use the interface to communicate with other products and services. API use has surged over the past decade, to the degree that many of the most popular web applications today would not be possible without APIs.

Node js Basics: ( https://www.w3schools.com/nodejs/)

  • Modules
  • File system
  • NPM
  • Email
  • MYSQL
  • MongoDB

What is REST API ? (https://www.sitepoint.com/developers-rest-api/)

An API, or application programming interface, is a set of rules that define how applications or devices can connect to and communicate with each other. A REST API is an API that conforms to the design principles of the REST, or representational state transfer architectural style.

Nodejs and MYSQL connection: ( https://www.youtube.com/watch?v=hGZX_SA7lYg)(https://www.w3schools.com/nodejs/nodejs_mysql.asp)

Nodejs and redis: (https://www.codementor.io/@brainyfarm/caching-with-redis-node-js-example-h6o9ii72i)(https://www.npmjs.com/package/ioredis)

Redis simplifies your code by enabling you to write fewer lines of code to store, access, and use data in your applications. For example, if your application has data stored in a hashmap, and you want to store that data in a data store – you can simply use the Redis hash data structure to store the data.

Nodejs and mongodb: (https://www.w3schools.com/nodejs/nodejs_mongodb_create_db.asp)

Nodejs and Moongoose: (https://www.npmjs.com/package/mongoose)

Noddjs and sequelize: (https://www.npmjs.com/package/sequelize)

Nodejs callback: (https://www.tutorialspoint.com/nodejs/nodejs_callbacks_concept.htm)

Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All the APIs of Node are written in such a way that they support callbacks.

Important nodejs libraries:

Async nodejs programming:(https://blog.logrocket.com/parallelism-concurrency-and-async-programming-in-node-js/)

Node.js uses an asynchronous event-driven design pattern, which means that multiple actions are taken at the same time while executing a program. For example, if there are two endpoints that follow one another in the program, the server will move one to make a request to the second endpoint without waiting for the first to return data.

restify framework: (http://restify.com/docs/server-api/)

restify is a node.js module built specifically to enable you to build correct REST web services. It intentionally borrows heavily from express as that is more or less the de facto API for writing web applications on top of node.js.

Restify-Errors(https://github.com/restify/errors)

Comparing similar libraries of nodejs.

Basic Understanding of github:(https://www.youtube.com/watch?v=77W2JSL7-r8)

github commands: https://youtu.be/eL_0Ok_Gkas

API testing tools:

Boilerplate: (https://github.com/bismay4u/Boilerplate-nodejs-api/blob/master/index.js)