NodeJS interview questions

NodeJS quiz questions

  • 1.

    Explain the steps how “Control Flow” controls the functions calls?


    a) Control the order of execution

    b) Collect data

    c) Limit concurrency

    d) Call the next step in program

  • 2.

    What is control flow function?


    A generic piece of code which runs in between several asynchronous function calls is known as control flow function.

  • 3.

    What are the two types of API functions in Node.js ?


    The two types of API functions in Node.js are

    a) Asynchronous, non-blocking functions

    b) Synchronous, blocking functions

  • 4.

    What is the advantage of using node.js?


    a) It provides an easy way to build scalable network programs

    b) Generally fast

    c) Great concurrency

    d) Asynchronous everything

    e) Almost never blocks

  • 5.

    Where can we use node.js?


    Node.js can be used for the following purposes

    a) Web applications ( especially real-time web apps )

    b) Network applications

    c) Distributed systems

    d) General purpose applications

  • 6.

    What does event-driven programming mean?


    In computer programming, event driven programming is a programming paradigm in which the flow of the program is determined by events like messages from other programs or threads. It is an application architecture technique divided into two sections
    1) Event Selection
    2) Event Handling

  • 7.

    What do you mean by the term I/O ?


    I/O is the shorthand for input and output, and it will access anything outside of your application. It will be loaded into the machine memory to run the program, once the application is started.

  • 8.

    How node.js works?


    Node.js works on a v8 environment, it is a virtual machine that utilizes JavaScript as its scripting language and achieves high output via non-blocking I/O and single threaded event loop.

  • 9.

    What's your favourite HTTP framework and why?


    There is no right answer for this. The goal here is to understand how deeply one knows the framework she/he uses, if can reason about it, knows the pros, cons.

  • 10.

    What's a test pyramid? How can you implement it when talking about HTTP APIs?


    A test pyramid describes that when writings test cases there should be a lot more low-level unit tests than high level end-to-end tests.

    When talking about HTTP APIs, it may come down to this:

    • a lot of low-level unit tests for your models
    • less integration tests, where your test how your models interact with each other
    • a lot less acceptance tests, where you test the actual HTTP endpoints
  • 11.

    What's a stub? Name a use case.


    Stubs are functions/programs that simulate the behaviours of components/modules. Stubs provide canned answers to function calls made during test cases. Also, you can assert on with what these stubs were called.

    A use-case can be a file read, when you do not want to read an actual file:

    var fs = require('fs');
    var readFileStub = sinon.stub(fs, 'readFile', function (path, cb) {  
      return cb(null, 'filecontent');
  • 12.

    Why npm shrinkwrap is useful?


    It is useful when you are deploying your Node.js applications - with it you can be sure which versions of your dependencies are going to be deployed.

  • 13.

    What's the difference between operational and programmer errors?


    Operation errors are not bugs, but problems with the system, like request timeout or hardware failure.

    On the other hand programmer errors are actual bugs.

  • 14.

    What tools can be used to assure consistent style?


    You have plenty of options to do so:

    These tools are really helpful when developing code in teams, to enforce a given style guide and to catch common errors using static analysis.

  • 15.

    What's the event loop?


    Node.js runs using a single thread, at least from a Node.js developer's point of view. Under the hood Node.js uses many threads through libuv.

    Every I/O requires a callback - once they are done they are pushed onto the event loop for execution. If you need a more detailed explanation, I suggest viewing this video.

  • 16.

    How can you listen on port 80 with Node?


    Trick question! You should not try to listen with Node on port 80 (in Unix-like systems) - to do so you would need superuser rights, but it is not a good idea to run your application with it.

    Still, if you want to have your Node.js application listen on port 80, here is what you can do. Run the application on any port above 1024, then put a reverse proxy like nginx in front of it.

  • 17.

    How can you avoid callback hells?


    To do so you have more options:

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

    What is an error-first callback?


    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
  • 19.

    Consider following code snippet:

        for (var i = 0; i < 1000000; i += 1){
            // Do nothing

    The time required to run this code in Google Chrome is considerably more than the time required to run it in Node.js. Explain why this is so, even though both use the v8 JavaScript Engine.


    Within a web browser such as Chrome, declaring the variable i outside of any function’s scope makes it global and therefore binds it as a property of the window object. As a result, running this code in a web browser requires repeatedly resolving the property i within the heavily populated window namespace in each iteration of the for loop.

    In Node.js, however, declaring any variable outside of any function’s scope binds it only to the module’s own scope (not the window object) which therefore makes it much easier and faster to resolve.

  • 20.

    What is typically the first argument passed to a Node.js callback handler?


    Node.js core modules, as well as most of the community-published ones, follow a pattern whereby the first argument to any callback handler is an optional error object. If there is no error, the argument will be null or undefined.

    A typical callback handler could therefore perform error handling as follows:

    function callback(err, results) {
        // usually we'll check for the error before handling results
        if(err) {
            // handle error somehow and return
        // no error, perform standard callback handling

© 2017