Site icon DataFlair

Nodejs Interview Questions

nodejs interview questions

FREE Online Courses: Elevate Your Skills, Zero Cost Attached - Enroll Now!

This is the first part of the interview questions articles. Here you will find the most important questions that are asked in node js interview. For each question a detailed and efficient answer is provided. This article is beginner friendly containing the basics of nodejs.

Nodejs Interview Questions

1. What is npm about?
Ans. It is the most popularly used package manager. It installs different packages available for node.js.
Npm is a package manager for node.js which installs available packages into our project. It is a central repository for all available packages.

2. Is npm better than any other package manager?
Ans. Yes.

3. How can you start building a nodejs project?
Ans.

4.What is the main difference between installing a package globally as compared to installing it locally?
Ans. Local packages are present in the project directory, whereas global packages are kept in a single folder in your system
The local packages are not accessible outside the project whereas you can use the global packages in any project.

5. What are the contents present in the package.json file?
Ans.

6. What are dependencies?
Ans. Dependencies provide information regarding the packages we use in the project.

All the packages shown in the dependencies property are required to run the node js application.

It contains details about the package like version number, etc.

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

7. What is devdependencies ?
Ans. Devdependencies are very much similar with dependencies but the main difference is that the packages which are under the devdependency are necessary only during the development of our application.

We don’t require these dependencies when our application is in production.

8. What can you say about npm audit?
Ans. We install a lot of packages in our system and many times we unknowingly install harmful packages, so to identify these malicious packages npm audit is used. In order to fix the vulnerabilities, the npm audit fix command is run.

9. What do you understand about npm publish?
Ans. If you want your own modules to be available in https://www.npmjs.com/ than you need to publish them using the “npm publish” command. Once it is published everybody will be able to install it using the “npm install <your package name>” command.

10. What are core modules in nodejs?
Ans. Modules that are part of nodejs and installed automatically with the Node.js installation process are called core modules.

To include this module in our program we use the require function.

Eg: let name= require(‘name’)

The return type of require() function depends on what the module returns.

11. What do you mean by Local module?
Ans. Modules that are created by us locally are local modules. Local modules are imported in our program in the same way as we include the built in module.

The Exports keyword is used to make methods available in our module to outside the file.

In order to include this method/function in our file, we use the require function.

12. Describe the http methods.
Ans.

13. Describe the methods of make file?
Ans. Below are the different methods of make file:

14. What are the important modules of nodejs?
Ans. Below are the important modules of nodejs:

15. How can you modify a file?
Ans. The fs.appendFile() method takes the text that we want to append, then it appends at the end of the file. If the file does not exist then the file will be created.

fs.writeFile() is for replacing the content of the file.

Summary:

This was all about nodejs interview questions and answers. It covers most important interview questions which are common in a nodejs interview.

Exit mobile version