Author: saqibkhan

  • What are streams in Node.js?

    Streams are objects that enable you to read data or write data continuously.

    There are four types of streams:

    Readable – Used for reading operations

    Writable − Used for write operations

    Duplex − Can be used for both reading and write operations

    Transform − A type of duplex stream where the output is computed based on input

  • What is the Express.js package?

    Express is a flexible Node.js web application framework that provides a wide set of features to develop both web and mobile applications

  • What is the package.json file?

    The package.json file is the heart of a Node.js system. This file holds the metadata for a particular project. The package.json file is found in the root directory of any Node application or module

    This is what a package.json file looks like immediately after creating a Node.js project using the command: npm init

    You can edit the parameters when you create a Node.js project.

    node-npm
  • How would you use a URL module in Node.js?

    The URL module in Node.js provides various utilities for URL resolution and parsing. It is a built-in module that helps split up the web address into a readable format.

    varurl
  • What are the two types of API functions in Node.js?

    The two types of API functions in Node.js are:

    • Asynchronous, non-blocking functions
    • Synchronous, blocking functions
  • What is an Event Loop in Node.js?

    Event loops handle asynchronous callbacks in Node.js. It is the foundation of the non-blocking input/output in Node.js, making it one of the most important environmental features.

  •  Differentiate between process.nextTick() and setImmediate()?

    The distinction between method and product. This is accomplished through the use of nextTick() and setImmediate(). next Tick() postpones the execution of action until the next pass around the event loop, or it simply calls the callback function once the event loop’s current execution is complete, whereas setImmediate() executes a callback on the next cycle of the event loop and returns control to the event loop for any I/O operations.

  • What is an EventEmitter in Node.js?

    • EventEmitter is a class that holds all the objects that can emit events
    • Whenever an object from the EventEmitter class throws an event, all attached functions are called upon synchronously
    /eventemitter
  • What does event-driven programming mean?

    An event-driven programming approach uses events to trigger various functions. An event can be anything, such as typing a key or clicking a mouse button. A call-back function is already registered with the element executes whenever an event is triggered.

  • What are the pros and cons of Node.js?

    Node.js ProsNode.js Cons
    Fast processing and an event-based modelNot suitable for heavy computational tasks
    Uses JavaScript, which is well-known amongst developersUsing callback is complex since you end up with several nested callbacks
    Node Package Manager has over 50,000 packages that provide the functionality to an applicationDealing with relational databases is not a good option for Node.js
    Best suited for streaming huge amounts of data and I/O intensive operationsSince Node.js is single-threaded, CPU intensive tasks are not its strong suit