NodeJS is an open-source and cross-platform runtime atmosphere constructed on Chrome’s V8 JavaScript engine for executing JavaScript code outdoors of a browser. It is advisable to recollect that NodeJS isn’t a framework, and it’s not a programing language. It offers an event-driven, non-blocking (asynchronous) I/O and cross-platform runtime atmosphere for constructing extremely scalable server-side functions utilizing JavaScript.
We’ve already created Fundamental Stage NodeJS Interview Questions and Solutions – Set 1
This set comprises the intermediate-level questions requested within the interview.
1. What’s event-driven programming in Node.js?
Occasion-driven programming is used to synchronize the incidence of a number of occasions and to make this system so simple as doable. The essential elements of an Occasion-Pushed Program are:
- A callback perform ( referred to as an occasion handler) known as when an occasion is triggered.
- An occasion loop that listens for occasion triggers and calls the corresponding occasion handler for that occasion.
2. What’s buffer in Node.js?
The Buffer class in Node.js is used to carry out operations on uncooked binary information. Usually, Buffer refers back to the specific reminiscence location in reminiscence. Buffer and array have some similarities, however the distinction is array might be any kind, and it may be resizable. Buffers solely cope with binary information, and it can’t be resizable. Every integer in a buffer represents a byte. console.log() perform is used to print the Buffer occasion.
3. What are streams in Node.js?
Streams are a sort of data-handling methodology and are used to learn or write enter into output sequentially. Streams are used to deal with studying/writing recordsdata or exchanging info in an environment friendly manner. The stream module offers an API for implementing the stream interface. Examples of the stream object in Node.js generally is a request to an HTTP server and course of.stdout are each stream cases.
4. Clarify crypto module in Node.js
The crypto module is used for encrypting, decrypting, or hashing any kind of information. This encryption and decryption mainly assist to safe and add a layer of authentication to the information. The primary use case of the crypto module is to transform the plain readable textual content to an encrypted format and decrypt it when required.
5. What’s callback hell?
Callback hell is a matter precipitated attributable to a nested callback. This causes the code to appear like a pyramid and makes it unable to learn To beat this case we use guarantees.
6. Clarify using timers module in Node.js?
The Timers module in Node.js comprises varied features that permit us to execute a block of code or a perform after a set time period. The Timers module is world, we don’t want to make use of require() to import it.
It has the next strategies:
7. Distinction between setImmediate() and course of.nextTick()
The method.nextTick() methodology is used so as to add a brand new callback perform in the beginning of the subsequent occasion queue. it’s referred to as earlier than the occasion is processed. The setImmediate known as on the test part of the subsequent occasion queue. It’s created within the ballot part and is invoked through the test part.
8. What’s the distinction between setTimeout() and setImmediate() methodology?
The setImmediate perform is used to execute a specific script instantly whereas the setTimeout perform is used to carry a perform and execute it after a specified time period.
9. What’s the distinction between spawn() and fork() methodology?
Each these strategies are used to create new baby processes the one distinction between them is that spawn() methodology creates a brand new perform that Node runs from the command line whereas fork() perform creates an occasion of the prevailing fork() methodology and creates a number of staff to carry out on the identical process.
10. Clarify using passport module in Node.js
The passport module is used for including authentication options to our web site or internet app. It implements authentication measure which helps to carry out sign-in operations.
11. What’s fork in Node.js?
Fork is a technique in Node.js that’s used to create baby processes. It helps to deal with the growing workload. It creates a brand new occasion of the engine which permits a number of processes to run the code.
12. What are the three strategies to keep away from callback hell?
The three strategies to keep away from callback hell are:
- Utilizing async/await()
- Utilizing guarantees
- Utilizing turbines
13. What’s body-parser in Node.js?
Physique-parser is the Node.js body-parsing middleware. It’s accountable for parsing the incoming request our bodies in a middleware earlier than you deal with it. It’s an NPM module that processes information despatched in HTTP requests.
14. What’s CORS in Node.js?
The phrase CORS stands for “Cross-Origin Useful resource Sharing”. Cross-Origin Useful resource Sharing is an HTTP-header primarily based mechanism carried out by the browser which permits a server or an API to point any origins (totally different by way of protocol, hostname, or port) apart from its origin from which the unknown origin will get permission to entry and cargo sources. The cors bundle obtainable within the npm registry is used to deal with CORS errors in a Node.js utility.
15. Clarify the tls module in Node.js?
The tls module offers an implementation of the Transport Layer Safety (TLS) and Safe Socket Layer (SSL) protocols which can be constructed on high of OpenSSL. It helps to ascertain a safe connection on the community.
16. What’s using url module in Node.js?
In Node.js url module is used to separate the URL of the web site into components in order that it turns into readable and can be utilized within the totally different components of the appliance. The parse() methodology is used with the url module to separate the URL of the web site into components.
17. What’s REST API?
Representational State Switch (REST) is an architectural type that defines a set of constraints for use for creating internet providers. REST API is a manner of accessing internet providers in a easy and versatile manner with out having any processing. It really works after the request is distributed from the shopper to the server within the type of an online URL as HTTP GET or POST or PUT or DELETE request. After that, a response comes again from the server within the type of a useful resource which might be something like HTML, XML, Picture, or JSON. However now JSON is the preferred format being utilized in Internet Providers.
18. Clarify the engine Google makes use of for Node.js?
The engine utilized by Google for Node.js is V8. It’s one the quickest engine as it’s written in C++. It offers a runtime atmosphere for the execution of JavaScript code. The very best half is that the JavaScript engine is totally impartial of the browser wherein it runs. It has an enormous group and is extremely moveable.
19. Identify the device used for writing constant code?
ESLint is a device utilized in many IDEs to write down constant code types. ESLint is written utilizing Node.js to offer a quick runtime atmosphere and simple set up by way of npm.
20. What are the totally different sorts of HTTP requests?
Essentially the most generally used HTTP requests are:
- GET: This request is used to learn/retrieve information from an online server. GET returns an HTTP standing code of 200 (OK) if the information is efficiently retrieved from the server.
- PUT: This request is used to switch the information on the server. It replaces all the content material at a specific location with information that’s handed within the physique payload. If there aren’t any sources that match the request, it is going to generate one.
- POST: This request is used to ship information (file, kind information, and so on.) to the server. On profitable creation, it returns an HTTP standing code of 201.
- DELETE: This request is used to delete the information on the server at a specified location.
Final Up to date :
07 Jun, 2023
Like Article
Save Article