Explain the steps how “Control Flow” controls the functions calls?
Answer:
a) Control the order of execution
b) Collect data
c) Limit concurrency
d) Call the next step in program
ViewWhat is control flow function?
Answer:
A generic piece of code which runs in between several asynchronous function calls is known as control flow function.
ViewWhat are the two types of API functions in Node.js ?
Answer:
The two types of API functions in Node.js are
a) Asynchronous, non-blocking functions
b) Synchronous, blocking functions
ViewWhat is the advantage of using node.js?
Answer:
a) It provides an easy way to build scalable network programs
b) Generally fast
c) Great concurrency
d) Asynchronous everything
e) Almost never blocks
ViewWhere can we use node.js?
Answer:
Node.js can be used for the following purposes
a) Web applications ( especially real-time web apps )
b) Network applications
c) Distributed systems
d) General purpose applications
ViewWhat does event-driven programming mean?
Answer:
In computer programming, event driven programming is a programming paradigm in which the flow of the program is determined by events like messages from other programs or threads. It is an application architecture technique divided into two sections
1) Event Selection
2) Event Handling
What do you mean by the term I/O ?
Answer:
I/O is the shorthand for input and output, and it will access anything outside of your application. It will be loaded into the machine memory to run the program, once the application is started.
ViewHow node.js works?
Answer:
Node.js works on a v8 environment, it is a virtual machine that utilizes JavaScript as its scripting language and achieves high output via non-blocking I/O and single threaded event loop.
ViewWhat's your favourite HTTP framework and why?
Answer:
There is no right answer for this. The goal here is to understand how deeply one knows the framework she/he uses, if can reason about it, knows the pros, cons.
ViewWhat's a test pyramid? How can you implement it when talking about HTTP APIs?
Answer:
A test pyramid describes that when writings test cases there should be a lot more low-level unit tests than high level end-to-end tests.
When talking about HTTP APIs, it may come down to this:
What's a stub? Name a use case.
Answer:
Stubs are functions/programs that simulate the behaviours of components/modules. Stubs provide canned answers to function calls made during test cases. Also, you can assert on with what these stubs were called.
A use-case can be a file read, when you do not want to read an actual file:
var fs = require('fs');
var readFileStub = sinon.stub(fs, 'readFile', function (path, cb) {
return cb(null, 'filecontent');
});
expect(readFileStub).to.be.called;
readFileStub.restore();
View
Why npm shrinkwrap is useful?
Answer:
It is useful when you are deploying your Node.js applications - with it you can be sure which versions of your dependencies are going to be deployed.
ViewWhat's the difference between operational and programmer errors?
Answer:
Operation errors are not bugs, but problems with the system, like request timeout or hardware failure.
On the other hand programmer errors are actual bugs.
ViewWhat tools can be used to assure consistent style?
Answer:
You have plenty of options to do so:
These tools are really helpful when developing code in teams, to enforce a given style guide and to catch common errors using static analysis.
ViewWhat's the event loop?
Answer:
Node.js runs using a single thread, at least from a Node.js developer's point of view. Under the hood Node.js uses many threads through libuv.
Every I/O requires a callback - once they are done they are pushed onto the event loop for execution. If you need a more detailed explanation, I suggest viewing this video.
ViewHow can you listen on port 80 with Node?
Answer:
Trick question! You should not try to listen with Node on port 80 (in Unix-like systems) - to do so you would need superuser rights, but it is not a good idea to run your application with it.
Still, if you want to have your Node.js application listen on port 80, here is what you can do. Run the application on any port above 1024, then put a reverse proxy like nginx in front of it.
ViewHow can you avoid callback hells?
Answer:
To do so you have more options:
yield
with Generators and/or PromisesWhat is an error-first callback?
Answer:
Error-first callbacks are used to pass errors and data. The first argument is always an error object that the programmer has to check if something went wrong. Additional arguments are used to pass data.
fs.readFile(filePath, function(err, data) {
if (err) {
//handle the error
}
// use the data object
});
View
Consider following code snippet:
{
console.time("loop");
for (var i = 0; i < 1000000; i += 1){
// Do nothing
}
console.timeEnd("loop");
}
The time required to run this code in Google Chrome is considerably more than the time required to run it in Node.js. Explain why this is so, even though both use the v8 JavaScript Engine.
Answer:
Within a web browser such as Chrome, declaring the variable i
outside of any function’s scope makes it global and therefore binds it as a property of the window
object. As a result, running this code in a web browser requires repeatedly resolving the property i
within the heavily populated window
namespace in each iteration of the for
loop.
In Node.js, however, declaring any variable outside of any function’s scope binds it only to the module’s own scope (not the window
object) which therefore makes it much easier and faster to resolve.
What is typically the first argument passed to a Node.js callback handler?
Answer:
Node.js core modules, as well as most of the community-published ones, follow a pattern whereby the first argument to any callback handler is an optional error object. If there is no error, the argument will be null or undefined.
A typical callback handler could therefore perform error handling as follows:
function callback(err, results) {
// usually we'll check for the error before handling results
if(err) {
// handle error somehow and return
}
// no error, perform standard callback handling
}
View
© 2017 QuizBucket.org