Node.js Flashcards

1
Q

What is Node.js?

A
  • Node.js is a web application framework built on Google Chrome’s JavaScript Engine (V8 Engine).
  • Node.js comes with runtime environment on which a Javascript based script can be interpreted and executed (It is analogus to JVM to JAVA byte code). This runtime allows to execute a JavaScript code on any machine outside a browser. Because of this runtime of Node.js, JavaScript now can be executed on a server as well.
  • Node.js = Runtime Environment + JavaScript Library
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

The two types of API functions in Node.js are:

  • Asynchronous, non-blocking functions
  • Synchronous, blocking functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is npm?

A

npm stands for Node Package Manager. npm provides the following two main functionalities:

  • Online repositories for node.js packages/modules which are searchable on search.nodejs.org
  • Command-line utility to install packages, do version management and dependency management of Node.js packages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is global installation of dependencies?

A

Globally installed packages/dependencies are stored in /npm directory. Such dependencies can be used in CLI (Command Line Interface) function of any Node.js but can not be imported using require() in Node application directly. To install a Node project globally use -g flag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Callback?

A

Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All APIs of Node are written is such a way that they supports callbacks.

For example, a function to read a file may start reading file and return the control to execution environment immediately so that next instruction can be executed. Once file I/O is complete, it will call the callback function while passing the callback function, the content of the file as parameter. So there is no blocking or wait for File I/O.

This makes Node.js highly scalable, as it can process high number of request without waiting for any function to return result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List out the differences between Angular.js and Node.js?

A

AngularJS is a web application development framework. It’s JavaScript and it is different from other web app frameworks written in JavaScript like jQuery.

NodeJS is a runtime environment used for building server-side applications while AngularJS is a JavaScript framework mainly useful in building/developing client-side part of applications which run inside a web browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the key features of Node.js?

A
  • Asynchronous event driven IO helps concurrent request handling – All APIs of Node.js are asynchronous. This feature means that if a Node receives a request for some Input/Output operation, it will execute that operation in the background and continue with the processing of other requests. Thus it will not wait for the response from the previous requests.
  • Fast in Code execution – Node.js uses the V8 JavaScript Runtime engine, the one which is used by Google Chrome. Node has a wrapper over the JavaScript engine which makes the runtime engine much faster and hence processing of requests within Node.js also become faster.
  • Single Threaded but Highly Scalable – Node.js uses a single thread model for event looping. The response from these events may or may not reach the server immediately. However, this does not block other operations. Thus making Node.js highly scalable. Traditional servers create limited threads to handle requests while Node.js creates a single thread that provides service to much larger numbers of such requests.
  • Node.js library uses JavaScript – This is another important aspect of Node.js from the developer’s point of view. The majority of developers are already well-versed in JavaScript. Hence, development in Node.js becomes easier for a developer who knows JavaScript.
  • There is an Active and vibrant community for the Node.js framework – The active community always keeps the framework updated with the latest trends in the web development.
  • No Buffering – Node.js applications never buffer any data. They simply output the data in chunks.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an error-first callback?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do you mean by Asynchronous API?

A

All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between Node.js, AJAX, and jQuery?

A

The one common trait between Node.js, AJAX, and jQuery is that all of them are the advanced implementation of JavaScript. However, they serve completely different purposes.

  • Node.js –It is a server-side platform for developing client-server applications. For example, if we’ve to build an online employee management system, then we won’t do it using client-side JS. But the Node.js can certainly do it as it runs on a server similar to Apache, Django not in a browser.
  • 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. There are a no. of large companies utilizing AJAX such as Facebook and Stack Overflow to display dynamic content.
  • jQuery –It is a famous JavaScript module which complements AJAX, DOM traversal, looping and so on. This library provides many useful functions to help in JavaScript development. However, it’s not mandatory to use it but as it also manages cross-browser compatibility, so can help you produce highly maintainable web applications.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the core modules of Node.js?

A
  • EventEmitter
  • Stream
  • FS
  • Net
  • Global Objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the benefits of using Node.js?

A

Following are main benefits of using Node.js

  • Aynchronous and Event Driven - All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.
  • Very Fast - Being built on Google Chrome’s V8 JavaScript Engine, Node.js library is very fast in code execution.
  • Single Threaded but highly Scalable - Node.js uses a single threaded model with event looping. Event mechanism helps server to respond in a non-bloking ways and makes server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and same program can services much larger number of requests than traditional server like Apache HTTP Server.
  • No Buffering - Node.js applications never buffer any data. These applications simply output the data in chunks.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Callback Hell?

A

The asynchronous function requires callbacks as a return parameter. When multiple asynchronous functions are chained together then callback hell situation comes up.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the control flow function?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between returning a callback and just calling a callback?

A

See image!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is libuv?

A

libuv is a C library that is used to abstract non-blocking I/O operations to a consistent interface across all supported platforms. It provides mechanisms to handle file system, DNS, network, child processes, pipes, signal handling, polling and streaming. It also includes a thread pool for offloading work for some things that can’t be done asynchronously at the operating system level.

17
Q

What is V8?

A

The V8 library provides Node.js with a JavaScript engine (a program that converts Javascript code into lower level or machine code that microprocessors can understand), which Node.js controls via the V8 C++ API. V8 is maintained by Google, for use in Chrome.

The Chrome V8 engine :

  • The V8 engine is written in C++ and used in Chrome and Nodejs.
  • It implements ECMAScript as specified in ECMA-262.
  • The V8 engine can run standalone we can embed it with our own C++ program.