Node.js is a Server side scripting which is used to build scalable programs. Its multiple advantages over other server side languages, the prominent being non-blocking I/O.
2) Where can we use node.js?
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
3) What is the advantage of using node.js?
- a) It provides an easy way to build scalable network programs
- b) Generally fast
- c) Great concurrency
- d) Asynchronous everything
- e) Almost never blocks
4) What are the two types of API functions in Node.js ?
The two types of API functions in Node.js are
- a) Asynchronous, non-blocking functions
- b) Synchronous, blocking functions
5) What is control flow function?
A generic piece of code which runs in between several asynchronous function calls is known as control flow function.
6) Why Node.js is single threaded?
For async processing, Node.js was created explicitly as an experiment. It is believed that more performance and scalability can be achieved by doing async processing on a single thread under typical web loads than the typical thread based implementation.
7) Can you access DOM in node?
No, you cannot access DOM in node.
8) Using the event loop what are the tasks that should be done asynchronously?
- a) I/O operations
- b) Heavy computation
- c) Anything requiring blocking
9) Why node.js is quickly gaining attention from JAVA programmers?
10) What is ‘Callback’ in node.js?
Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don’t want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.
11) Mention the framework most commonly used in node.js?
“Express” is the most common framework used in node.js
12) What is an event loop in Node.js ?
To process and handle external events and to convert them into callback invocations an event loop is used. So, at I/O calls, node.js can switch from one request to another .
13) Mention the steps by which you can async in Node.js?
By following steps you can async Node.js
- a) First class functions
- b) Function composition
- c) Callback Counters
- d) Event loops
14) What are the pros and cons of Node.js?
b) Crawlers receive a full-rendered HTML response, which is far more SEO friendly rather than a single page application or a websockets app run on top of Node.js.
a) Any intensive CPU computation will block node.js responsiveness, so a threaded platform is a better approach.
b) Using relational database with Node.js is considered less favourable
15) How Node.js overcomes the problem of blocking of I/O operations?
Node.js solves this problem by putting the event based model at its core, using an event loop instead of threads.
16) What is the difference between Node.js vs Ajax?
17) What are the Challenges with Node.js ?
Emphasizing on the technical side, it’s a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.
18) What does it mean “non-blocking” in node.js?
19) What is the command that is used in node.js to import external libraries?
Command “require” is used for importing external libraries, for example, “var http=require (“http”)”. This will load the http library and the single exported object through the http variable.
20) What’s your favourite HTTP framework and why?
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.
21)What’s the difference between operational and programmer errors?
Operation errors are not bugs, but problems with the system, likerequest timeout or hardware failure.
On the other hand programmer errors are actual bugs.
22) What is the latest version of Node.js available?
Latest version of Node.js is – v0.10.36.
23) What are the features of Node.js?
Below are the features of Node.js –
- Very Fast
- Event driven and Asynchronous
- Single Threaded but highly Scalable
24) Explain REPL in Node.js?
REPL stands for Read Eval Print Loop. Node.js comes with bundled REPL environment which performs the following desired tasks –
25) Explain variables in Node.js?
Variables are used to store values and print later like any conventional scripts. If “var” keyword is used then value is stored in variable. You can print the value in the variable using – console.log().
> a = 30
> var b = 50
> a + b
26) List out some REPL commands in Node.js?
Below are the list of REPL commands –
- Ctrl + c – For terminating the current command.
- Ctrl + c twice – For terminating REPL.
- Ctrl + d – For terminating REPL.
- Tab Keys – list of all the current commands.
- .break – exit from multiline expression.
- .save with filename – save REPL session to a file.
27) Mention the command to stop REPL in Node.js?
Command – ctrl + c twice is used to stop REPL.
28) Explain NPM in Node.js?
NPM stands for Node Package Manager (npm) and there are two functionalities which NPM takes care of mainly and they are –
- Online repositories for node.js modules or packages, which can be searched on search.nodejs.org
- Dependency Management, Version Management and command line utility for installing Node.js packages.
29) Mention command to verify the NPM version in Node.js?
Below command can be used to verify the NPM version –
$ npm –version
30) How you can update NPM to new version in Node.js?
Below commands can be used for updating NPM to new version –
$ sudo npm install npm -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
[email protected] /usr/lib/node_modules/npm
31) Explain callback in Node.js?
Callback is called once the asynchronous operation has been completed. Node.js heavily uses callbacks and all API’s of Node.js are written to support callbacks.
32) How Node.js can be made more scalable?
Node.js works good for I/O bound and not CPU bound work. For instance if there is a function to read a file, file reading will be started during that instruction and then it moves onto next instruction and once the I/O is done or completed it will call the callback function. So there will not be any blocking.
33) Explain global installation of dependencies?
Globally installed dependencies or packages are stored in <user-directory>/npm directory and these dependencies can be used in Command Line Interface function of any node.js.
34) What you mean by chaining in Node.JS?
It’s a mechanism in which output of one stream will be connected to another stream and thus creating a chain of multiple stream operations.
35) Explain Child process module?
Child process module has following three major ways to create child processes –
- spawn – child_process.spawn launches a new process with a given command.
- exec – child_process.exec method runs a command in a shell/console and buffers the output.
- fork – The child_process.fork method is a special case of the spawn() to create child processes.
36) Why to use exec method for Child process module?
“exec” method runs a command in a shell and buffers the output. Below is the command –
child_process.exec(command[, options], callback)
37) List out the parameters passed for Child process module?
Below are the list of parameters passed for Child Process Module –
child_process.exec(command[, options], callback)
- command – This is the command to run with space-separated arguments.
- options – This is an object array which comprises one or more following options –
callback – This is the function which is gets 2 arguments – stdout, stderr and error.
38) What is the use of method – “spawn()”?
This method is used to launch a new process with the given commands. Below is the method signature –
child_process.spawn(command[, args][, options])
39) What is the use of method – “fork()”?
This method is a special case for method- “spawn()” for creating node processes. The method signature –
child_process.fork(modulePath[, args][, options])
40) Explain Piping Stream?
This is a mechanism of connecting one stream to other and this is basically used for getting the data from one stream and pass the output of this to other stream.
41) What would be the limit for Piping Stream?
There will not be any limit for piping stream.
42) Explain FS module ?
Here FS stands for “File System” and fs module is used for File I/O. FS module can be imported in the following way –
var test = require(“fs”)
43) Explain “Console” in Node.JS?
“Console” is a global object and will be used for printing to stderr and stdout and this will be used in synchronous manner in case of destination is either file or terminal or else it is used in asynchronous manner when it is a pipe.
44) Explain – “console.log([data][, …])” statement in Node.JS?
This statement is used for printing to “stdout” with newline and this function takes multiple arguments as “printf()”.
45) List out the properties of process?
Below are the useful properties of process –
46) How to concatenate buffers in NodeJS?
The syntax to concatenate buffers in NodeJS is
var MyConctBuffer = Buffer.concat([myBuffer1, myBuffer2]);
47) How to compare buffers in NodeJS?
To compare buffers in NodeJS, use following code –
48) How to copy buffers in NodeJS?
Below is the syntax to copy buffers in NodeJS –
buffer.copy(targetBuffer[, targetStart][, sourceStart][, sourceEnd])
49) What are the differences between “readUIntBE” and “writeIntBE” in Node.JS?
- readUIntBE – It’s a generalized version of all numeric read methods, which supports up to 48 bits accuracy. Setting noAssert to “true” to skip the validation.
- writeIntBE – This will write the value to the buffer at the specified byteLength and offset and it supports upto 48 bits of accuracy.
50)Why to use “SetTimeout” in Node.JS?
This is the global function and it is used to run the callback after some milliseconds.
Syntax of this method –