Node.js Interview Questions and Answers (18) - Page 1

Identify the below command for knowing Nodejs version?

NOTE: This is objective type question, Please click question title for correct answer.
Identify the features of Nodejs

NOTE: This is objective type question, Please click question title for correct answer.
What kind of application NodeJS is suitable for?

NOTE: This is objective type question, Please click question title for correct answer.
Identify the features of ExpressJS

NOTE: This is objective type question, Please click question title for correct answer.
How to check if node is properly installed in the system?

NOTE: This is objective type question, Please click question title for correct answer.
What is Gulp?

NOTE: This is objective type question, Please click question title for correct answer.
What is Bower?

NOTE: This is objective type question, Please click question title for correct answer.
What is Nodemon?

NOTE: This is objective type question, Please click question title for correct answer.
What is the command for installing the node utilities like Gulp, Bower and Nodemon in the system?

NOTE: This is objective type question, Please click question title for correct answer.
What is the purpose of package.json?

All npm packages contain a json file which is located at the root of the project. This json file is the package.json .It that holds various metadata (e.g. project description,project dependencies, project version,license information etc. ) relevant to the project. It allows npm to identify the project as well as handle the project's dependencies. A sample package.json may look as under

{

"name": "EmployeeCRUDUsingMERN",
"version": "1.0.0",
"description": "A example of Package.json",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "RNA Team",
"license": "ISC",
"dependencies": {
"browserify": "^12.0.1",
"express": "^4.13.3",
"guid": "0.0.12",
"gulp": "^3.9.0",
"react": "^0.14.5",
"react-dom": "^0.14.5",
"reactify": "^1.1.1",
"vinyl-source-stream": "^1.1.0"
}
}

What is the purpose of bower.json ?

It is the manifest file for bower packages.Bower is a package manager which manage components that comprises of HTML, CSS, JavaScript frameworks and libraries, utilities, fonts, image files etc. It helps to maintain the right versions of the packages we need and their dependencies. e.g.

{

"name": "EmployeeCRUDUsingMERN",
"description": "Example of Bower.json",
"main": "index.js",
"authors": [
"RNA Team"
],
"license": "ISC",
"moduleType": [
"node"
],
"homepage": "",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bootstrap-css": "~3.3.4",
"jquery": "~2.1.1"
}
}


The example shows that, there is a dependency on bootstrap and jquery library.
What is browserify?

NOTE: This is objective type question, Please click question title for correct answer.
What does CommonJs module pattern do?

CommonJs module pattern helps to add references to various js libraries as opposed to adding script tags in individual html pages thereby prevents all the UI pages from being getting polluted.The CommonJs module pattern only allowed one module per file - it there by eliminates circular dependencies and helps in finding out the properties regarding the current module.

e.g.

// ourpackage is a dependency needed in the project

var lib = require('ourpackage');

// perform some action
function Print(){
lib.log('it is only a test');
}

// export Print to other modules
exports.Print = Print;

What is the purpose of vinyl-source-stream?

vinyl-source-stream converts the readable stream from browserify into a vinyl stream which gulp expects. It is a Virtual file format that gulp expects so that it does not create a temporal file while making the transformation.
What is “callback hell” and how can it be avoided?

“Callback hell” refers to heavily nested callbacks that have become unwieldy or unreadable.

Example:
query("SELECT clientId FROM clients WHERE clientName='picanteverde';", function(id){

query("SELECT * FROM transactions WHERE clientId=" + id, function(transactions){
transactions.each(function(transac){
query("UPDATE transactions SET value = " + (transac.value*0.1) + " WHERE id=" + transac.id, function(error){
if(!error){
console.log("success!!");
}else{
console.log("error");
}
});
});
});
});


The primary method to fix callback hell is usually referred to as modularization. The callbacks are broken out into independent functions which can be called with some parameters. So the first level of improvement might be:

var logError = function(error){

if(!error){
console.log("success!!");
}else{
console.log("error");
}
},
updateTransaction = function(t){
query("UPDATE transactions SET value = " + (t.value*0.1) + " WHERE id=" + t.id, logError);
},
handleTransactions = function(transactions){
transactions.each(updateTransaction);
},
handleClient = function(id){
query("SELECT * FROM transactions WHERE clientId=" + id, handleTransactions);
};

query("SELECT clientId FROM clients WHERE clientName='picanteverde';",handleClient);

NPM stands for?

NOTE: This is objective type question, Please click question title for correct answer.
The Maximum time span can be set in the Timer in setTimeout(a,b)?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories