Node js Interview Questions And Answers

What is Node.js?

Node.js is lightweight, efficient plateform built on Chrome's Javascript runtime for easily building fast, scalable network aplications.
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.
What you will do to stop the server from running?

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

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

These are the following datatypes of Node.js -
Number, Boolean, String, Object.
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.
Is it possible to define a class in Node.js?

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

We can call a module in node.js by using require function.
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.
What is npm?

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

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

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

fs.readFile('filename', function(err, contents){
What is module?

Modules are a way to group common functionality in Node.js.
What is the command to read the content of a file? command is used to read the content of a file.
What is the command to open a file? command is used to open a file.
How to install latest version of express using npm?

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

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

Console is global variable and log is its function.
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.
What is the need of http module?

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

This function is called whenever somebody makes a connection to server. It takes only one argument.
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.
What is prototype?

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

Anything attach to the global object is available anywhere in your node application.
global.animal = "dog";
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.
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.
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.
Write syntax of updating express module.

$npm update module
What is Buffer Class?

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

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

What are Streams?

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

There are four types of streams - Readable, Writable, Duplex and Transform.
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.
How to import a file system module?

By using the following syntax, we can import the file system module -
var fs = require("fs");
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.
How to stop a timer that are previously created?

By using clearTimeout(t) global function, we can stop a timer that was previously created.
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.
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");
What is the Response object?

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