Express and Node JS Interview Questions

Node JS Interview Questions with Express Download Node JS Interview Questions with Express PDF

Node JS Interview Questions with Express

Aggregations are a set of functions that are used to manipulate the data that has been returned from a MongoDB query. In Mongoose, aggregations work as a pipeline. The aggregate function accepts the array of data transformations which are applied by data using different methods in terms of arguments.

Syntax: db.customers.aggregate([ ... aggregation steps go here ...]);

In above, aggregation is applied to data of customers.

The main difference between the put and the patch is

The embedded entity is believed to the modified version of the resources that are deposited on the original server. It is requested to the client to replace the stored is substituted.In this, the information regarding the way of modifying the original server which has the resources to produce a new version is found.
At the time of updating the resource, you need to forward full payload as the request.At the time of updating the resource, you only need to send the parameter of the resource which you want to update.

Http defines a set of request methods to perform the desired actions. These request methods are:

  1. GET: The GET method asked for the representation of the specifies resource. This request used to retrieve the data.
  2. POST: The POST technique is utilized to present an element to the predetermined resource, generally causing a change in state or reactions on the server.
  3. HEAD: The HEAD method is similar to the GET method but asks for the response without the response body.
  4. PUT: This method is used to substitute all current representations with the payload.
  5. DELETE: It is used to delete the predetermined resource.
  6. CONNECT: This request is used to settle the TCP/IP tunnel to the server by the target resource
  7. OPTION: This method is used to give back the HTTP strategies to communicate with the target resource.
  8. TRACE: This method echoes the message which tells the customer how much progressions have been made by an intermediate server.
  9. PATCH: The PATCH method gives partial modifications to a resource.

Revealing module pattern is similar to Module Pattern.IT ExposES only the properties and methods you want via an returned Object.

var greeting = 'Hello world'
function greet() {
module.exports = {
  greet: greet

CommonJS Modules is the Standard how to code modules are structured. It specifies an ecosystem for JavaScript outside on the server or for native desktop applications.

There is no notion of any database in Express JS. So, the concept of models is left up to third-party node modules, allowing the users to interface with nearly any type of database.

In Express JS, there are two ways for configuring the properties:

  • With process.ENV:
  • A file with the name “.env” is to be created inside the project folder.
  • All the properties are to be added in the “.env” file.
  • Any of the properties can be used in server.js.
  • With require JS:
  • A file with the name “config.json” is to be created in the config folder inside the project folder.
  • The config properties are to be added in the config.json file.
  • Now, require should be used to access the config.json file.

Since authentication is an opinionated area which is not ventured by express JS, therefore any authentication scheme can be used in express JS for the authentication of users.

The arguments which are available to an Express JS route handler-function are-

  • Req – the request object
  • Res – the response object
  • Next (optional) – a function which is used to pass control to one of the subsequent route handlers.

The third argument is optional and may be omitted, but in some cases, it is useful where there is a chain of handlers and control can be passed to one of the subsequent route handlers skipping the current one.

Express JS supports any template engine that conforms to the (path, locals, callback) signature.

Single-page, multi-page, and hybrid web applications can be built using Express JS.

There’s no need to render HTML with the res.render () function. If there’s a specific file, then you should use the res.sendFile () function. If any assets are being served from a dictionary, then express.static () middleware function needs to be used.

Express.js is a lightweight web application which helps in organizing the web application into MVC architecture on the server side.

Below are the few reasons why to use Express with Node.js

  • Express js is built on top of Node.js. It is the perfect framework for ultra-fast Input / Output.
  • Cross Platform
  • Support MVC Design pattern
  • Support of NoSQL databases out of the box.
  • Multiple templating engine support i.e. Jade or EJS which reduces the amount of HTML code you have to write for a page.
  • Support Middleware, basic web-server creation, and easy routing tools.