TPointTech Node Flashcards
What Node js timers are there?
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
Node Js faces fout types of errors. Name and explain them
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>
What are the commonly used Node DNS?
What is Nodejs Net and how is it related to socket programming?
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.
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?
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.
Node.js TLS/SSL
What is TLS/SSL?
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.
What is public key crptography?
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’);
What is Node.js debugger?
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.
What is a Node js process?
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.
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?
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.
What are Buffers?
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.
Node.js Streams
What are streams?
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:
What does it mean with piping Streams?
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.
What do we mean with Node js chaining Streams?
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.
Node.js File System(FS). What is that?
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.