NODE-JS & EXPRESS-JS INTERVIEW QUESTION ANSWER

 

Nodejs


1) What is node js?

Node js is a free and open-source server technology that uses Javascript to create complete web software. It runs on various platforms like Windows, Linux, Unix, Mac OS X, etc.
You can also use it for developing: Real-time web applications, Network applications, General-purpose applications, and Distributed systems.

2. Why use Node.js?

Node.js makes building scalable network programs easy. Some of its advantages include:

1.     It is generally fast

2.     It rarely blocks

3.     It offers a unified programming language and data type

4.     Everything is asynchronous

3) Explain CLI in Node.js?

CLI stands for Command Line Interface. It is a utility or program on your computer where users type commands to perform some action or run some script rather than clicking on the screen.

There are different types of command line interfaces depending on which operating system you are using. We have listed some of them below.

1.     Bash on Linux.

2.     Terminal of Mac.

3.     Command Prompt or Powershell on Windows

4.     Shell/ Command line/terminal on Unix and Ubuntu

4) Why is Node.js Single-threaded?

Node.js is single-threaded for async processing. By doing async processing on a single-thread under typical web loads, more performance and scalability can be achieved instead of the typical thread-based implementation.

5) In which Language Node Js is written?

 Node js is written in C, C++,JavaScript.It uses Google’s open-source V8 Javascript Engine to convert Javascript code to C++.

6) Explain What is a Javascript Engine?

A Javascript Engine is a program that converts code written in Javascript to something that a computer processor understands. 

7) Explain callback in Node.js?

A callback function is called after a given task. It allows other code to be run in the meantime and prevents any blocking.  Being an asynchronous platform, Node.js heavily relies on callback. All APIs of Node are written to support callbacks.

8) .What is NPM?

NPM stands for Node Package Manager, responsible for managing all the packages and modules for Node.js.

Node Package Manager provides two main functionalities:

1.     Provides online repositories for node.js packages/modules, which are searchable on search.nodejs.org

2.     Provides command-line utility to install Node.js packages and also manages Node.js versions and dependencies .

9) Explain Modules in Node Js ?

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. 

10) What are CommonJs Modules ?

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.

11) What does emitter do and what is dispatcher?

An Emitter class can be used to raise and handle custom events. It facilitates interaction between objects in Node.

A Dispatcher is a service object that is used to ensure that the Event is passed to all relevant Listeners.

12) Since node is a single threaded process, how to make use of all CPUs?

You can use the cluster module. Node Js is supporting clustering to take full advantage of your CPU.

13) What do you mean by Express JS?

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.

14) Name the type of web applications which can be built using Express JS.

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

15) What is the use of Express JS?

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

16) What function are arguments available to Express JS route handlers?

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.

17) How to config properties in Express JS?

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

1.     With process.ENV:

2.     A file with the name “.env” is to be created inside the project folder.

3.     All the properties are to be added in the “.env” file.

4.     Any of the properties can be used in server.js.

5.     With require JS:

6.     A file with the name “config.json” is to be created in the config folder inside the project folder.

7.     The config properties are to be added in the config.json file.

8.     Now, require should be used to access the config.json file.

18) How can models be defined in Express JS?

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.

19) How to authenticate users in express JS?

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.

20) Which template engine is supported by express JS?

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

21) How can plain HTML be rendered in 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.

22) Why to use Express.js?

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

1.     Support MVC Design pattern

2.     Support of NoSQL databases out of the box.

3.     Multiple templating engine support i.e. Jade or EJS which reduces the amount of HTML code you have to write for a page.

4.     Support Middleware, basic web-server creation, and easy routing tools.

23) Explain the difference between readFile and createReadStream in Node js ?

readFile load the whole file which you had marked to read whereas createReadStream reads the complete file in the parts of the size you have declared.

The client will receive the data faster in the case of createReadStream in contrast with readFile.

In readFile, a file will first completely read by memory and then transfers to a client but in later option, a file will be read by memory in a part which is sent to clients and the process continue until all the parts finish.

24) List types of Http requests?

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

GET: The GET method asked for the representation of the specifies resource. This request used to retrieve the data.

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.

HEAD: The HEAD method is similar to the GET method but asks for the response without the response body.

PUT: This method is used to substitute all current representations with the payload.

DELETE: It is used to delete the predetermined resource.

CONNECT: This request is used to settle the TCP/IP tunnel to the server by the target resource

OPTION: This method is used to give back the HTTP strategies to communicate with the target resource.

TRACE: This method echoes the message which tells the customer how much progressions have been made by an intermediate server.

PATCH: The PATCH method gives partial modifications to a resource.

24) What is the purpose of the module. exports?

A module in Node.js is used to encapsulate all the related codes into a single unit of code, which can be interpreted by shifting all related functions into a single file. You can export a module using the module.exports, which allows it to be imported into another file using a required keyword.

25) What is the control flow function?

The control flow function is a piece of code that runs in between several asynchronous function calls.

26) What is the buffer class in Node.js?

Buffer class stores raw data similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. Buffer class is used because pure JavaScript is not compatible with binary data.

27) Differentiate between Node.js vs Ajax?

The major difference between Nodes.js and Ajax is –

Nodes.js is a server-side platform for developing client-server applications, whereas Ajax is a client-side scripting technique that was basically designed to show the contents of a page without refreshing it.

 28) What is a test pyramid in Node.js?

A test pyramid is a metaphor that is used to make a bunch of software tests of different granularity. For example, unit testing, component testing, integration testing, system testing, end-to-end testing, UI testing.

29) Explain the concept of middleware in Node.js.

Middleware is a function that has the access to the requested object, requested response and the next function in the application’s request-response cycle. The middleware function can perform multiple tasks such as; execute code, make changes to the request and the response objects, end the request-response cycle and call the next middleware in the stack.

30) What is REPL in Node.js?

REPL stands for Read-Eval-Print-Loop. This is a virtual environment that comes with Node.js. It is a quick and easy way to test simple Node.js codes.

Post a Comment

0 Comments