Express and Node JS Interview Questions

Express and Node JS Interview Questions Download Express and Node JS Interview Questions PDF

Express and Node JS Interview Questions

By writing following line of code, you can create a server in Node Js.
var http =require('http');
http.createServer(function(req,res){

res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello World\n');

}).listen(1320,'127.0.0.3');
Use node -v command to check the installed version of Node Js.

JIT stands for Just-in-time. A JIT compiler is a program which is used to send bytecode (it consists of instruction that can be interpreted) to the processor by converting it into instruction. After you have done with writing a program, the compiler compiles the source language statements into bytecode instead of compiling it into the code that carries the information which is similar to the specific hardware platform's processor.

Relation of JIT with Node: Virtual machine of Nodejs has JIT compilation which improves the execution speed of the code. The virtual machine takes the source code and converts to machine code in runtime. By this, the hot functions which are called very often are compiled to machine code and, hence increasing speed.

A Closure is a function defined within another scope that has access to all the variables within the outer scope.

Global variables can be made local (private) with closures.

 

Modules are reusable block of code whose existence does not impact other code in any way. It is not supported by Javascript. Modules are introduced in ES6. Modules are important for Maintainability, Reusability, and Namespacing of Code.

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.

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.

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

NPM stands for node package manager. It is default Package Manager for JavaScript programming language. NPM is used for installing/updating packages and modules of Javascript.

Express JS is an application framework which is light-weighted node JS. A number of flexible, useful and important features are provided by this JavaScript framework for the development of mobile as well as web applications with the help of node JS.

Following are the list of few new Features introduced in ES6

  • const and let keywords
  • Array helper functions like map, forEach, filter, find, every, some, reduce
  • Arrow functions
  • Classes and enhanced object literals
  • Template strings
  • Default function arguments
  • Rest and spread operators
  • Promises
  • Modules
  • Multi-line Strings
  • Destructuring Assignment

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() {
 console.log(greeting)
}
module.exports = {
  greet: greet
}