NodeJS interview questions

NodeJS quiz questions

  • 1.

    How can you avoid callback hells?

    Answer:

    To do so you have more options:

    • modularization: break callbacks into independent functions
    • use Promises
    • use yield with Generators and/or Promises
    View
  • 2.

    What is an error-first callback?

    Answer:

    Error-first callbacks are used to pass errors and data. The first argument is always an error object that the programmer has to check if something went wrong. Additional arguments are used to pass data.

    fs.readFile(filePath, function(err, data) {  
      if (err) {
        //handle the error
      }
      // use the data object
    });
    View
  • 3.

    What are the benefits of using Node.js?

    Answer:

    Following are main benefits of using Node.js

    • Aynchronous and Event DrivenAll APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.

    • Very Fast Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution.

    • Single Threaded but highly Scalable - Node.js uses a single threaded model with event looping. Event mechanism helps server to respond in a non-bloking ways and makes server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and same program can services much larger number of requests than traditional server like Apache HTTP Server.

    • No Buffering - Node.js applications never buffer any data. These applications simply output the data in chunks.

    View
  • 4.

    Explain Asynchronous API?

    Answer:

    All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.

    View
  • 5.

    What is Node.JS?

    Answer:

    Node.js is a web application framework built on Google Chrome's JavaScript Engine(V8 Engine).

    Node.js comes with runtime environment on which a Javascript based script can be interpreted and executed (It is analogus to JVM to JAVA byte code). This runtime allows to execute a JavaScript code on any machine outside a browser. Because of this runtime of Node.js, JavaScript is now can be executed on server as well.

    Node.js also provides a rich library of various javascript modules which eases the developement of web application using Node.js to great extents.

     

    Node.js = Runtime Environment + JavaScript Library

    View

© 2017 QuizBucket.org