Node.js Interview Questions Part - 4

17.  What is the File system module in Node.js?

Answer:

Node.js file system provides the functionality to work with file in our local computer. The require('fs') function must be included when we are using file module.

Following are the common use of File System module.

Read files:
fs.readFile() method is used for reading file.

Create files:
Below methods are used to create file in Node.js.
  • fs.appendFile()
  • fs.open()
  • fs.writeFile()
Update files:
Following methods are used to update file.
  • fs.appendFile()
  • fs.writeFile()
Delete files:
We use fs.unlink() method for deleting the file

Rename files:
fs.rename() is used to rename the file.

18.  What is express and why to use express?

Answer:

Express framework facilitates the rapid development of Node based Web applications. Express is the light-weight web application framework used to build single page application, multipage application and hybrid web application.

It allows dynamic rendering of HTML Pages, based on arguments passed to templates.

Reason to use Express:

We should use Express because of following features.

  • It supports the Routing, session, configuration in the web application.
  • It also supports content navigation, error handling etc.
  • Express supports multiple databases like MySQL, MS SQL, MongoDB etc.

19.  What is template engine? Advantages of Template engine?

Answer:

Template engine helps to create an HTML template with minimal code. It injects data into HTML template at client side and produces the final HTML.

Advantages of Template engine in Node.js:

  • It improves developer's productivity with faster performance.
  • It improves readability and maintainability.
  • It maximizes client side processing.
  • Single template for multiple pages.
  • Templates can be accessed from CDN.

20.  What is the meaning of "non-blocking" in Node.js?

Answer:

Non-blocking code are those which doesn't wait for previous assign task to complete. Non-blocking code means that the IO is not blocking.

Node.js operates on single-thread, but non-blocking I/O calls allows it to support many concurrent connections.

21.  What is Test Driven Development (TDD)?

Answer:

TDD is the test first development approach.

Test Driven Development (TDD) is a programming practice that instructs developers to write new code only if an automated test has failed. This avoids duplication of code. The primary goal of TDD is to make the code clearer, simple and bug free

These are the following sequence we generally followed in TDD approach.

  • Add a test
  • Run all tests and see if the new one fails
  • Write some changes
  • Run tests
  • Refactor code
  • Repeat