Node.js

1. What is Node.js?

Answer:
Node.js is a JavaScript runtime environment used to run JavaScript code outside the browser. It is mainly used for backend development and server-side applications. Node.js is built on Chrome’s V8 engine which makes it fast and efficient. It supports scalable and real-time web applications.

2. What tools can be used to assure a consistent style in Node.js?

Following is a list of tools that can be used in developing code in teams, to enforce a given style guide and to catch common errors using static analysis.

  • JSLint
  • JSHint
  • ESLint
  • JSCS

3. What is the purpose of Node.js?

These are the following purposes of Node.js:

  • Real-time web applications
  • Network applications
  • Distributed systems
  • General purpose applications

4. What is Non-Blocking I/O in Node.js?

Answer:
Non-Blocking I/O allows Node.js to execute multiple operations simultaneously without waiting for one task to complete. It improves server speed and application performance. Users can continue using the application while background tasks are processed. This feature makes Node.js suitable for high-traffic applications.

5. What is Express.js?

Answer:
Express.js is a lightweight backend framework built on top of Node.js. It helps developers create APIs, routes, and web applications easily. Express.js simplifies backend coding and improves application structure. It is one of the most popular frameworks used in Node.js development.

6. What are some commonly used timing features of Node.js?

Following is a list of some commonly used timing features of Node.js:

  • setTimeout/clearTimeout: This timing feature of Node.js is used to implement delays in the code execution.
  • setInterval/clearInterval: The setInterval or clearInterval timing feature is used to run a code block multiple times in the application.
  • setImmediate/clearImmediate: This timing feature of Node.js is used to set the execution of the code at the end of the event loop cycle.
  • nextTick: This timing feature sets the execution of code at the beginning of the next event loop cycle.

7. What is the use of package.json?

Answer:
package.json is a configuration file used in Node.js projects. It stores project details, dependencies, scripts, and version information. Developers use it to manage packages and run project commands. It is one of the most important files in a Node.js application.

8. What is the difference between JavaScript and Node.js?

Difference between JavaScript and Node.js

The following table specifies the crucial differences between JavaScript and Node.js:

Comparison features JavaScript Node.js
Type JavaScript is a programming language. More precisely, you can say that it is a scripting language used for writing scripts on the website. Node.js is an interpreter and run time environment for JavaScript.
Utility JavaScript is used for any client-side activity for a web application. Node.js is used for accessing or performing any non-blocking operation of any operating system.
Running Engine The running engine for JavaScript is Spider monkey (Firefox), JavaScript Core (Safari), V8 (Google Chrome), etc. The running engine for Node.js is V8 (Google Chrome).
Browser compatibility JavaScript can only be run in browsers. The Node.js code can be run outside the browser.
Platform dependency JavaScript is basically used on the client-side and is used in frontend development. Node.js is mostly used on the server-side and is used in server-side development.
HTML compatibility JavaScript is capable enough to add HTML and play with the DOM. Node.js is not compatible enough to add HTML tags.

9. What is the Event Loop in Node.js?

Answer:
The Event Loop is a mechanism that handles asynchronous operations in Node.js. It allows Node.js to execute non-blocking tasks efficiently. The Event Loop continuously checks and processes pending events and callbacks. It is one of the core features of Node.js performance.

10. What is REST API?

Answer:
REST API is a communication method used between frontend and backend applications. It uses HTTP methods like GET, POST, PUT, and DELETE for data operations. REST APIs help applications exchange data efficiently over the internet. They are widely used in modern full-stack development.

11. What is fs Module in Node.js?

Answer:
The fs module is a built-in Node.js module used for file system operations. It helps developers read, write, update, and delete files. The fs module supports both synchronous and asynchronous methods. It is commonly used for handling server-side files and data.

12. What is a Module in Node.js?

Answer:
A module is a reusable block of code in Node.js used to organize applications into separate files. Modules improve code readability and maintenance. Developers can export and import modules whenever needed. This helps create scalable and clean backend applications.

13. What is require() in Node.js?

Answer:
The require() function is used to import modules, packages, and files into a Node.js application. It helps developers reuse code across different files. require() works with the CommonJS module system in Node.js. It is commonly used for importing frameworks like Express.js.

14. What are the streams in Node.js?

The Streams are the objects that facilitate you to read data from a source and write data to a destination. There are four types of streams in Node.js:

  • Readable: This stream is used for reading operations.
  • Writable: This stream is used for write operations.
  • Duplex: This stream can be used for both reading and write operations.
  • Transform: It is a type of duplex stream where the output computes according to input.

15. What is JWT in Node.js?

Answer:
JWT stands for JSON Web Token and is used for secure authentication and authorization. It securely transfers user information between client and server. JWT tokens are commonly used after user login for protected routes. It improves security in modern web applications.

16. What is Authentication?

Answer:
Authentication is the process of verifying the identity of a user in an application. It ensures that only authorized users can access protected resources. Authentication commonly uses login credentials like email and password. It is important for protecting user accounts and private data.

17. What is dotenv Package?

Answer:
dotenv is a Node.js package used to manage environment variables securely. It stores sensitive information like API keys and database passwords inside a .env file. dotenv helps keep secret data separate from application code. It improves security and project configuration management.

18. How many types of API functions are available in Node.js?

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

  • Asynchronous, Non-blocking functions
  • Synchronous, Blocking functions

19. What is Async/Await in Node.js?

Answer:
Async/Await is a modern way to handle asynchronous operations in Node.js. It makes code cleaner, easier to read, and simple to debug. Async/Await works with Promises for handling async tasks. It helps avoid deeply nested callback functions.

20. What is the purpose of Node.js?

These are the following purposes of Node.js:

  • Real-time web applications
  • Network applications
  • Distributed systems
  • General purpose applications

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What is Node.js mainly used for?

Node.js is mainly used for building fast and scalable backend server applications.

Question 2

Which package manager is used in Node.js?

npm (Node Package Manager) is used to install and manage Node.js packages and dependencies.

Question 3

What is the purpose of Middleware in Express.js?

Middleware functions execute between request and response cycles for tasks like logging and authentication.

Question 4

Which method is used to import modules in Node.js?

The require() function is used to import modules and packages in Node.js applications.

Question 5

What does JWT stand for?

JWT is used for secure authentication and authorization in web applications.

Congratulations!

You've successfully mastered the knowledge check for "Node.js."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic React.js Next Topic Express.js