Skip to Content, PHP, MySQL, Javascript, Ajax, Htacces

Node.JS Interview Questions and Answers For Freshers Part-2

Be First!

nodejs11.What is global installation of dependencies?
Globally installed packages/dependencies are stored in <user-directory>/npm directory. Such dependencies can be used in CLI (Command Line Interface) function of any node.js but can not be imported using require() in Node application directly. To install a Node project globally use -g flag.

C:\Nodejs_WorkSpace>npm install express -g

12.What is local installation of dependencies?
By default, npm installs any dependency in the local mode. Here local mode refers to the package installation in node_modules directory lying in the folder where Node application is present. Locally deployed packages are accessible via require(). To install a Node project locally following is the syntax.

C:\Nodejs_WorkSpace>npm install express

13.How to check the already installed dependencies which are globally installed using npm?
Use the following command:

C:\Nodejs_WorkSpace>npm ls -g

14.What is Package.json?
package.json is present in the root directory of any Node application/module and is used to define the properties of a package.

15.Name some of the attributes of package.json?
Following are the attributes of Package.json

name – name of the package

version – version of the package

description – description of the package

homepage – homepage of the package

author – author of the package

contributors – name of the contributors to the package

dependencies – list of dependencies. npm automatically installs all the dependencies mentioned here in the node_module folder of the package.

repository – repository type and url of the package

main – entry point of the package

keywords – keywords

16.How to uninstall a dependency using npm?
Use following command to uninstall a module.

C:\Nodejs_WorkSpace>npm uninstall dependency-name

17.How to update a dependency using npm?
Update package.json and change the version of the dependency which to be updated and run the following command.

C:\Nodejs_WorkSpace>npm update

18.What is Callback?
Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All APIs of Node are written is such a way that they supports callbacks. For example, a function to read a file may start reading file and return the control to execution environment immidiately so that next instruction can be executed. Once file I/O is complete, it will call the callback function while passing the callback function, the content of the file as parameter. So there is no blocking or wait for File I/O. This makes Node.js highly scalable, as it can process high number of request without waiting for any function to return result.

19.What is a blocking code?
If application has to wait for some I/O operation in order to complete its execution any further then the code responsible for waiting is known as blocking code.

20.How Node prevents blocking code?
By providing callback function. Callback function gets called whenever corresponding event triggered.



Leave a Reply