Node js Interview Questions And Answers

1.
What is Node.js?

Node.js is lightweight, efficient plateform built on Chrome's Javascript runtime for easily building fast, scalable network aplications.
2.
What createServer function will do?

createServer function takes only one argument, and that is a function that will be called whenever somebody makes a connection to the server.
3.
What you will do to stop the server from running?

To stop a server from running, simply press Ctrl + C.
4.
How to end the debugger?

We can end the debugger by pressing Ctrl+d.
5.
How many datatypes of Node.js?

These are the following datatypes of Node.js -
Number, Boolean, String, Object.
6.
What are the uses of push and pop function?

push and pop function is used to add and remove items to the end of an array.
7.
Is it possible to define a class in Node.js?

Yes, We can define a class in Node.js as function.
8.
How to call a module in node.js?

We can call a module in node.js by using require function.
9.
What is callback function?

Callback function is called on completion of certain program. It has at least one parameter, either the success or failure status of the last operation.
10.
What is npm?

npm(Node package Manager) is a package manager for the JavaScript programming language.
11.
What is a blocking methods?

A blocking methods execute synchronously. It waits for I/O to complete.
12.
What is non blocking methods?

A non blocking methods execute asynchronously. This does not wait for I/O to complete.
13.
Write Callback syntax.

fs.readFile('filename', function(err, contents){
			console.log(contents);	
	});
14.
What is module?

Modules are a way to group common functionality in Node.js.
15.
What is the command to read the content of a file?

fs.read command is used to read the content of a file.
16.
What is the command to open a file?

fs.open command is used to open a file.
17.
How to install latest version of express using npm?

npm install express
18.
What is general format of URL Routing function?

app.method(url, functions_optional, request_handler_funtion)
19.
What is console.log?

Console is global variable and log is its function.
20.
What is three dots in REPL represent?

The three dots (...) in Node REPL means it need more input from you to complete the expression, statement or function.
21.
What is the need of http module?

The http module allows program to act as a web server.
22.
What createServer function do?

This function is called whenever somebody makes a connection to server. It takes only one argument.
23.
What is watch(expr)?

This is used to add the given expression to the watch list, which is shown whenever you step or move through anything in the debugger.
24.
What is prototype?

All objects in Javascript have a prototype object, which is mechanism through which they can inherit properties and methods.
25.
What is global object?

Anything attach to the global object is available anywhere in your node application.
global.animal = "dog";
26.
How to print assertion failure exception?

We can print assertion failure exception by using global function.
assert(cond, message)
When cond evaluates to false, it throw an AssertionFailure exception.
27.
What do you mean by Asynchronous and Event Driven?

It means a Node.js based server never waits for an API to return data. The Server moves to the next API after calling it.
28.
What is REPL stands for?

REPL stands for Read Eval Print Loop. It represents a computer environment like a Windows console or Unix/ Linux shell where a command is entered and the system responds with an output in an interactive mode.
29.
Write syntax of updating express module.

$npm update module
30.
What is Buffer Class?

Buffer class is a global class that can be accessed in an application without importing the buffer module.
31.
What is the syntax to read data from a Node Buffer?

buf.toString(encoding, start, end)
32.
What is the syntax to convert buffer to JSON?

buf.toJSON()
33.
What are Streams?

Streams are objects that let you read data from a source or write data to a destination in continuous fashion.
34.
How many types of streams?

There are four types of streams - Readable, Writable, Duplex and Transform.
35.
What is piping?

Piping is a mechanism where we provide the output of one stream as the input to another stream. It is normally used to get data from one stream and to pass the output of that stream to another stream.
36.
How to import a file system module?

By using the following syntax, we can import the file system module -
var fs = require("fs");
37.
How to delete a file in Node.js?

fs.unline(path, callback)
path - this is the file name including path.
callback - This is the callback function. No arguments other than a possible exception are given to the completion callback.
38.
How to stop a timer that are previously created?

By using clearTimeout(t) global function, we can stop a timer that was previously created.
39.
How to know the operating system related utility functions in Node.js?

By using OS Module, we can get all OS related utility functions in Node.js.
40.
What is the use of Net Module?

Net module is used to create both server and client. This module provides an asynchronous network wrapper and it can be imported using the following syntax -
var net = require("net");
41.
What is the Response object?

The response object represents the HTTP response that an Express app sends when it gets an HTTP request.




Read more articles


General Knowledge



Learn Popular Language