TPointTech Node Flashcards

1
Q

What Node js timers are there?

A

Node.js Timer functions are global functions. You don’t need to use require() function in order to use timer functions. Let’s see the list of timer functions.

Set timer functions:

setImmediate(): It is used to execute setImmediate.
setInterval(): It is used to define a time interval.
setTimeout(): It is used to execute a one-time callback after delay milliseconds.
Clear timer functions:

clearImmediate(immediateObject): It is used to stop an immediateObject, as created by setImmediate
clearInterval(intervalObject): It is used to stop an intervalObject, as created by setInterval
clearTimeout(timeoutObject): It prevents a timeoutObject, as created by setTimeout

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

Node Js faces fout types of errors. Name and explain them

A

Standard JavaScript errors i.e. <EvalError>, <SyntaxError>, <RangeError>, <ReferenceError>, <TypeError>, <URIError> etc.
System errors
User-specified errors
Assertion errors</URIError></TypeError></ReferenceError></RangeError></SyntaxError></EvalError>

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

What are the commonly used Node DNS?

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

What is Nodejs Net and how is it related to socket programming?

A

Node.js provides the ability to perform socket programming. We can create chat application or communicate client and server applications using socket programming in Node.js. The Node.js net module contains functions for creating both servers and clients.

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

Node js Crypto?
The Node.js Crypto module supports cryptography. It provides cryptographic functionality that includes a set of wrappers for open SSL’s hash HMAC, cipher, decipher, sign and verify functions.

What is Hash and HMAC?

A

What is Hash
A hash is a fixed-length string of bits i.e. procedurally and deterministically generated from some arbitrary block of source data.

What is HMAC
HMAC stands for Hash-based Message Authentication Code. It is a process for applying a hash algorithm to both data and a secret key that results in a single final hash.

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

Node.js TLS/SSL
What is TLS/SSL?

A

TLS stands for Transport Layer Security. It is the successor to Secure Sockets Layer (SSL). TLS along with SSL is used for cryptographic protocols to secure communication over the web.

TLS uses public-key cryptography to encrypt messages. It encrypts communication generally on the TCP layer.

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

What is public key crptography?

A

In public-key cryptography, each client and each server has two keys: public key and private key. Public key is shared with everyone and private key is secured. To encrypt a message, a computer requires its private key and the recipient’s public key. On the other hand, to decrypt the message, the recipient requires its own

You have to use require(‘tls’) to access this module.

Syntax:

var tls = require(‘tls’);

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

What is Node.js debugger?

A

Node.js provides a simple TCP based protocol and built-in debugging client. For debugging your JavaScript file, you can use debug argument followed by the js file name you want to debug.

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

What is a Node js process?

A

Node.js provides the facility to get process information such as process id, architecture, platform, version, release, uptime, upu usage etc. It can also be used to kill process, set uid, set groups, unmask etc.

The process is a global object, an instance of EventEmitter, can be accessed from anywhere.

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

The node.js child process module provides the ability to spawn child processes in a similar manner to popen(3). How do you create these child processes?

A

There are three major way to create child process:

child_process.exec() method: This method runs a command in a console and buffers the output.

child_process.spawn() method: This method launches a new process with a given command.

child_process.fork() method: This method is a special case of spawn() method to create child processes.

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

What are Buffers?

A

Node.js provides Buffer class to store raw data similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap.

Buffer class is used because pure JavaScript is not nice to binary data.

So, when dealing with TCP streams or the file system, it’s necessary to handle octet streams.

Buffer class is a global class. It can be accessed in application without importing buffer module.

Parameter explanation:

string: It specifies the string data to be written to buffer.

offset: It specifies the index of the buffer to start writing at. Its default value is 0.

length: It specifies the number of bytes to write. Defaults to buffer.length

encoding: Encoding to use. ‘utf8’ is the default encoding.

Return values from writing buffers:
This method is used to return number of octets written. In the case of space shortage for buffer to fit the entire string, it will write a part of the string.

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

Node.js Streams
What are streams?

A

Streams are the objects that facilitate you to read data from a source and write data to a destination. There are four types of streams in Node.js:

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

What does it mean with piping Streams?

A

Piping is a mechanism where output of one stream is used as input to another stream. There is no limit on piping operation.

Let’s take a piping example for reading from one file and writing it to another file.

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

What do we mean with Node js chaining Streams?

A

Chaining stream is a mechanism of creating a chain of multiple stream operations by connecting output of one stream to another stream. It is generally used with piping operation.

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

Node.js File System(FS). What is that?

A

In Node.js, file I/O is provided by simple wrappers around standard POSIX functions. Node File System (fs) module can be imported using following syntax:

Node.js FS Reading File
Every method in fs module has synchronous and asynchronous forms.

Asynchronous methods take a last parameter as completion function callback. Asynchronous method is preferred over synchronous method because it never blocks the program execution where as the synchronous method blocks.

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

Node.js Open a File

A
16
Q

What are the Flags for Read/Write?

A
17
Q

What is the Node.js Path used for?

A

The Node.js path module is used to handle and transform files paths. This module can be imported by using the following syntax:

18
Q

What is StringDecoder?

A

The Node.js StringDecoder is used to decode buffer into string. It is similar to buffer.toString() but provides extra support to UTF.

19
Q

What is a query string?

A

The Node.js Query String provides methods to deal with query string. It can be used to convert query string into JSON object and vice-versa.

To use query string module, you need to use require(‘querystring’).

20
Q

What is ZLIB?

A

The Node.js Zlib module is used to provide compression and decompression (zip and unzip) functionalities. It is implemented using Gzip and deflate/inflate.

21
Q

What is Assertion Testing?

A

The Node.js Assert is the most elementary way to write tests. It provides no feedback when running your test unless one fails. The assert module provides a simple set of assertion tests that can be used to test invariants. The module is intended for internal use by Node.js, but can be used in application code via require (‘assert’).

22
Q

What is V8?

A

V8 is an open source JavaScript engine developed by the Chromium project for the Google Chrome web browser. It is written in C++. Now a days, it is used in many projects such as Couchbase, MongoDB and Node.js.

The Node.js V8 module represents interfaces and event specific to the version of V8. It provides methods to get information about heap memory through v8.getHeapStatistics() and v8.getHeapSpaceStatistics() methods.

23
Q

What are callbacks?

A

Callback is an asynchronous equivalent for a function. It is called at the completion of each task. In Node.js, callbacks are generally used. All APIs of Node are written in a way to supports callbacks. For example: when a function start reading file, it returns the control to execution environment immediately so that the next instruction can be executed.

In Node.js, once file I/O is complete, it will call the callback function. 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.

24
Q

What are events?

A

In Node.js applications, Events and Callbacks concepts are used to provide concurrency. As Node.js applications are single threaded and every API of Node js are asynchronous. So it uses async function to maintain the concurrency.

Node uses observer pattern. Node thread keeps an event loop and after the completion of any task, it fires the corresponding event which signals the event listener function to get executed.

25
Q

What is Event driven Programming?

A

Node.js uses event driven programming. It means as soon as Node starts its server, it simply initiates its variables, declares functions and then simply waits for event to occur. It is the one of the reason why Node.js is pretty fast compared to other similar technologies.

There is a main loop in the event driven application that listens for events, and then triggers a callback function when one of those events is detected.

26
Q

What is the difference between Events and Callbacks?

A

Although, Events and Callbacks look similar but the differences lies in the fact that callback functions are called when an asynchronous function returns its result where as event handling works on the observer pattern. Whenever an event gets fired, its listener function starts executing.

Node.js has multiple in-built events available through events module and EventEmitter class which is used to bind events and event listeners.

27
Q

What is Punycode?

A

Punycode is an encoding syntax which is used to convert Unicode (UTF-8) string of characters to basic ASCII string of characters. Since host names only understand ASCII characters so Punycode is used. It is used as an internationalized domain name (IDN or IDNA). Let’s understand it with an example:

Assume if you search for mañana.com in your browser so your browser (which is IDNA enabled) first convert this to punycode xn–maana-pta.com because the character ñ is not allowed in regular domain name. It is not supported in older versions.

28
Q

What is Node.js TTY?

A
29
Q

What is a web server?

A

Web Server is a software program that handles HTTP requests sent by HTTP clients like web browsers, and returns web pages in response to the clients. Web servers usually respond with html documents along with images, style sheets and scripts.

Most of the web server support server side scripts using scripting language or redirect to application server which perform the specific task of getting data from database, perform complex logic etc. and then sends a result to the HTTP client through the Web server.

Apache web server is one of the most commonly used web server. It is an open source project.

30
Q

Define the application architecture

A

A web application can be divided in 4 layers:

Client Layer: The Client layer contains web browsers, mobile browsers or applications which can make HTTP request to the web server.
Server Layer: The Server layer contains Web server which can intercepts the request made by clients and pass them the response.
Business Layer: The business layer contains application server which is utilized by web server to do required processing. This layer interacts with data layer via data base or some external programs.
Data Layer: The Data layer contains databases or any source of data.