Node.JS Interview questions

Node.JS Interview questions

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

What is an event loop in Node.js ?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (37)

Section 1

(37 cards)

What is an event loop in Node.js ?

Front

To process and handle external events and to convert them into callback invocations an event loop is used. So, at I/O calls, node.js can switch from one request to another .

Back

Difference between setImmediate() vs setTimeout()

Front

setImmediate() is designed to execute a script once the current poll (event loop) phase completes. setTimeout() schedules a script to be run after a minimum threshold in ms has elapsed.

Back

How To Make Post Request In Node.Js?

Front

var request = require('request'); request.post( 'http://www.example.com/action', { form: { key: 'value' } }, function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) } } );

Back

What is the command that is used in node.js to import external libraries?

Front

Command "require" is used for importing external libraries, for example, "var http=require ("http")". This will load the http library and the single exported object through the http variable.

Back

How To Avoid Callback Hell In Node.Js?

Front

1. Make Your Program Modular. It proposes to split the logic into smaller modules. And then join them together from the main module to achieve the desired result. 2. Use Async Mechanism. The async module has <async.waterfall> API which passes data from one operation to other using the next callback. Another async API <async.map> allows iterating over a list of items in parallel and calls back with another list of results. Use Promises Mechanism. Promises give an alternate way to write async code. Implementing promises requires the use of <.then()> function which waits for the promise object to return. 4. Use Generators. Generators are lightweight routines, they make a function wait and resume via the yield keyword. Generator functions uses a special syntax <function* ()>.

Back

What Is Callback Hell?

Front

Callback hell is heavily nested callbacks which make the code unreadable and difficult to maintain.

Back

What are streams

Front

Streams are pipes that let you easily read data from a source and pipe it to a destination. Simply put, a stream is nothing but an EventEmitter and implements some specials methods.

Back

What is Streams in Node.js?

Front

Streams are pipes that let you easily read data from a source and pipe it to a destination. Simply put, a stream is nothing but an EventEmitter and implements some specials methods.

Back

How Node.js overcomes the problem of blocking of I/O operations?

Front

Node.js solves this problem by putting the event based model at its core, using an event loop instead of threads.

Back

What is the advantage of using node.js?

Front

a) It provides an easy way to build scalable network programs b) Generally fast c) Great concurrency d) Asynchronous everything e) Almost never blocks

Back

What is 'Callback' in node.js?

Front

Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don't want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.

Back

What are the Challenges with Node.js ?

Front

Emphasizing on the technical side, it's a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.

Back

What is package.json? What is it used for?

Front

This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies. Some of the fields are: name, name, description, author and dependencies.

Back

What is REPL in Node.js

Front

REPL means Read-Eval-Print-Loop.

Back

Why Node.js is single threaded?

Front

For async processing, Node.js was created explicitly as an experiment. It is believed that more performance and scalability can be achieved by doing async processing on a single thread under typical web loads than the typical thread based implementation.

Back

Why node.js is quickly gaining attention from JAVA programmers?

Front

Node.js is quickly gaining attention as it is a loop based server for JavaScript. Node.js gives user the ability to write the JavaScript on the server, which has access to things like HTTP stack, file I/O, TCP and databases.

Back

What is Node.js? What is it used for?

Front

Node.js is a run-time JavaScript environment built on top of Chrome's V8 engine. It uses an event-driven, non-blocking I/O model.

Back

What is process.nextTick()

Front

More precisely, process.nextTick() defers the function until a completely new stack. You can call as many functions as you want in the current stack. The function that called nextTick has to return, as well as its parent, all the way up to the root of the stack. Then when the event loop is looking for a new event to execute, your nextTick'ed function will be there in the event queue and execute on a whole new stack.

Back

What is Event-driven programming

Front

Event-driven programming is building our application based on and respond to events So all the callback functions are queued in an loop, and will run one-by-one when the response has been received.

Back

Mention the steps by which you can async in Node.js?

Front

a) First class functions b) Function composition c) Callback Counters d) Event loops

Back

How To Get Post Data In Node.Js?

Front

app.use(express.bodyParser()); app.post('/', function(request, response){ console.log(request.body.user); });

Back

Can You Create HTTP Server In Nodejs, Explain The Code Used For It?

Front

var http = require('http'); var requestListener = function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Welcome Viewers
'); } var server = http.createServer(requestListener); server.listen(8080); // The port where you want to start with.

Back

Can you access DOM in node?

Front

No, you cannot access DOM in node.

Back

Using the event loop what are the tasks that should be done asynchronously?

Front

a) I/O operations b) Heavy computation c) Anything requiring blocking

Back

Mention the framework most commonly used in node.js?

Front

"Express" is the most common framework used in node.js

Back

What is control flow function?

Front

A generic piece of code which runs in between several asynchronous function calls is known as control flow function.

Back

What is Tracing in Node.js

Front

Tracing provides a mechanism to collect tracing information generated by V8, Node core and userspace code in a log file. Tracing can be enabled by passing the --trace-events-enabled flag when starting a Node.js application.

Back

What Is The Difference Between Nodejs, AJAX, And JQuery?

Front

Node.Js - It is a server-side platform for developing client-server applications. AJAX (Aka Asynchronous Javascript And XML) - It is a client-side scripting technique, primarily designed for rendering the contents of a page without refreshing it.

Back

What Is The Global Installation Of Dependencies?

Front

Globally installed packages/dependencies are stored in <user-directory>/npm directory. Such dependencies can be used in CLI (Command Line Interface) function of any node.js, but cannot be imported using require() in the Node application directly. C:\Nodejs_WorkSpace>npm install express -g

Back

What is the difference between Asynchronous and Non-blocking?

Front

Non-Blocking This term is mostly used with IO. What this means is that when you make a system call, it will return immediately with whatever result it has without putting your thread to sleep (with high probability). Asynchronous literally means not synchronous. Email is asynchronous. You send a mail, you don't expect to get a response NOW. But it is not non-blocking. Essentially what it means is an architecture where "components" send messages to each other without expecting a response immediately.

Back

What are the pros and cons of Node.js?

Front

Pros: a) If your application does not have any CPU intensive computation, you can build it in Javascript top to bottom, even down to the database level if you use JSON storage object DB like MongoDB. b) Crawlers receive a full-rendered HTML response, which is far more SEO friendly rather than a single page application or a websockets app run on top of Node.js. Cons: a) Any intensive CPU computation will block node.js responsiveness, so a threaded platform is a better approach. b) Using relational database with Node.js is considered less favourable

Back

What are the two arguments that async.queue takes?

Front

a) Task function b) Concurrency value

Back

What are the two types of API functions in Node.js ?

Front

a) Asynchronous, non-blocking functions b) Synchronous, blocking functions

Back

Explain the steps how "Control Flow" controls the functions calls?

Front

a) Control the order of execution b) Collect data c) Limit concurrency d) Call the next step in program

Back

What Is A Control Flow Function? What Are The Steps Does It Execute?

Front

It is a generic piece of code which runs in between several asynchronous function calls is known as control flow function. Control the order of execution. Collect data. Limit concurrency. Call the next step in the program.

Back

What is the difference between Node.js vs Ajax?

Front

The difference between Node.js and Ajax is that, Ajax (short for Asynchronous Javascript and XML) is a client side technology, often used for updating the contents of the page without refreshing it. While,Node.js is Server Side Javascript, used for developing server software. Node.js does not execute in the browser but by the server.

Back

What is the purpose of module.exports in Node.js?

Front

A module encapsulates related code into a single unit of code. This can be interpreted as moving all related functions into a file

Back