NodeJS Interview Questions
NodeJS Interview Questions
Ans. https://blog.bitsrc.io/6-best-practices-to-improve-node-js-security-d5796381b019
https://www.mindinventory.com/blog/nodejs-security-best-practices/
https://www.simform.com/blog/nodejs-security/
Ans.
https://www.freecodecamp.org/news/node-js-child-processes-everything-you-need-to-kn
ow-e69498fe970a/
https://www.geeksforgeeks.org/node-js-child-process/
Q3. Sql query for find the second largest age from database.
Ans. SELECT MAX(age) from users where age < SELECT MAX(age) from users
Ans:-
https://anywhere.epam.com/business/node-js-pros-and-cons.
https://www.simform.com/blog/nodejs-advantages-disadvantages/
https://www.mindinventory.com/blog/pros-and-cons-of-node-js-web-app-development/
Q5. What is the disadvantage of recursive function?
Ans.
https://www.educative.io/courses/recursion-for-coding-intervi
ews-in-cpp/qAx1lwQYDNG
ANS.
https://www.boardinfinity.com/blog/top-10-features-of-es6/
ANS.
https://www.geeksforgeeks.org/difference-between-put-and-p
atch-request/
ANS.
https://betterprogramming.pub/6-major-features-of-node-js-2
0-741a206cb84
https://www.bacancytechnology.com/blog/whats-new-in-node
-20
(1) How does node js process multiple requests at a time?
Before getting into the Node server architecture, to take a look at typical
multithreaded request-response model, the web server would have multiple
threads and when concurrent requests get to the webserver, the webserver
picks threadOne from the threadPool and threadOne processes
requestOne and responds to clientOne and when the second request
comes in, the web server picks up the second thread from the threadPool
and picks up requestTwo and processes it and responds to clientTwo.
threadOne is responsible for all kinds of operations that requestOne
demanded including doing any blocking IO operations.
The fact that the thread needs to wait for blocking IO operations is what
makes it inefficient. With this kind of a model, the webserver is only able to
serve as many requests as there are threads in the thread pool.
Resources:
https://medium.com/skyshidigital/6-tricks-to-speed-up-and-improve-your-no
de-js-performance-fadc06d15cbe
(3) How node js Event Loop internally works ?
https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/
● Also since we will use Javascript in both the frontend and backend the
development will be much faster.
● And at last, there are ample libraries so that we don’t need to reinvent the wheel.
We can use either of both. But I use promise because structure of code is well.
And we can easily read the code.
Callback: This is the callback where all the task results are passed and is executed once
all the task execution has been completed.
An example of parallel:
async.parallel(
[
function(callback) {
setTimeout(function() {
console.log('Task One');
callback(null, 1);
}, 200);
},
function(callback) {
setTimeout(function() {
console.log('Task Two');
callback(null, 2);
}, 100);
],
function(err, results) {
console.log(results);
});
task1: function(callback) {
setTimeout(function() {
console.log('Task One');
callback(null, 1);
}, 200);
},
task2: function(callback) {
setTimeout(function() {
console.log('Task Two');
callback(null, 2);
}, 100);
}, function(err, results) {
console.log(results);
});
Async.series: When we have to run multiple tasks which depend on the output of the
previous task, series comes to our rescue.
Callback function receives an array of result objects when all the tasks have
been completed. If an error is encountered in any of the task, no more
functions are run but the final callback is called with the error value.
Example:
async.series
([
function(callback) {
console.log('one');
callback(null, 1);
},
function(callback) {
console.log('two');
callback(null, 2);
},
function(callback) {
console.log('three');
callback(null, 3);
],
function(err, results) {
console.log(result);
});
async.series({
1: function(callback) {
setTimeout(function() {
console.log('Task 1');
callback(null, 'one');
}, 200);
},
2: function(callback) {
setTimeout(function() {
console.log('Task 2');
callback(null, 'two');
}, 300);
},
3: function(callback) {
setTimeout(function() {
console.log('Task 3');
callback(null, 'three');
}, 100);
}
},
function(err, results) {
console.log(results);
});
Callback: This is the callback where all the task results are passed and is
executed once all the task execution has completed.
It will run one function at a time and pass the result of the previous function to
the next one.
Example:
async.waterfal
l([
function(callback) {
},
callback(null, arg3);
},
function(arg1, callback) {
callback(null, arg1);
], function(err, result) {
console.log(result);
});
async.waterfall([
myFirstFunction,
mySecondFunction,
myLastFunction,
], function(err, result) {
// result now equals 'Task1 and Task2
completed'
console.log(result);
});
function myFirstFunction(callback) {
callback(null, arg3);
callback(null, arg1);
Reference :
https://www.velotio.com/engineering-blog/understanding-node-js-async-flows-parallel-s
erial-waterfall-and-queues
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Displayin
g_data/flow_control_using_async#why_is_this_needed
Promise.all() will reject immediately upon any of the input promises rejecting.
Example:
If the iterable contains non-promise values, they will be ignored, but still
counted in the returned promise array value (if the promise is fulfilled):
(10) What are the globles which are directly provided from
nodejs ?
Node.js global objects are global in nature and they are available in
all modules. We do not need to include these objects in our application,
rather we can use them directly. These objects are modules, functions,
strings and object itself as explained below.
Middleware function is use request object, response object, and next function. So
I think we can use middleware for response object.
Approach 2: Using Process: A good practice says, you should use Process to
handle exceptions. A process is a global object that provides information about
the current Node.js process. The process is a listener function that is always
listening to the events.
The most effective and efficient approach is to use Process.
(13) API methods like POST, GET, PUT all about it.
An HTTP method is idempotent if an identical request can be made
once or several times in a row with the same effect while leaving the server
in the same state. In other words, an idempotent method should not have
any side-effects (except for keeping statistics). Implemented correctly, the
GET, HEAD, PUT, and DELETE methods are idempotent, but not the POST
method. All safe methods are also idempotent.
POST : The HTTP POST method sends data to the server. The type of the
body of the request is indicated by the Content-Type header. The
difference between PUT and POST is that PUT is idempotent: calling it once
or several times successively has the same effect (that is no side effect),
where successive identical POST may have additional effects, like passing
an order several times.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
Resources:
https://www.geeksforgeeks.org/difference-between-npm-and-yarn/
Resources:
https://www.geeksforgeeks.org/difference-between-dependencies-devdepe
ndencies-and-peerdependencies/
It depends where you are using node.js in your apps and how
sensitive are they.
Resources:
https://stackoverflow.com/questions/34829167/what-is-the-difference-betwe
en-the-lts-version-and-the-stable-version-of-node-js
We can use either of both. But I use promise because structure of code is well.
And we can
We can use either of both. But I use promise because structure of code is well.
And we can
1. https://www.interviewbit.com/node-js-interview-questions/
2. https://www.simplilearn.com/tutorials/nodejs-tutorial/nodejs-interview-questions
3. https://github.com/learning-zone/nodejs-interview-questions
19. What is the difference between library and framework?
https://www.interviewbit.com/blog/framework-vs-library/
https://www.shiksha.com/online-courses/articles/framework-vs-library/
ANS. https://www.codingninjas.com/codestudio/library/streams-and-buffer-in-node-js
ANS.
https://www.geeksforgeeks.org/what-is-web-socket-and-how-it-is-different-from-the-htt
p/