NodeJS interview questions

NodeJS quiz questions

  • 1.

    What is the use of Underscore variable in REPL?

    Answer:

    Use _ to get the last result.

    C:\Nodejs_WorkSpace>node
    > var x = 10
    undefined
    > var y = 20
    undefined
    > x + y
    30
    > var sum = _
    undefined
    > console.log(sum)
    30
    undefined
    >
    View
  • 2.

    What is the difference of using var and not using var in REPL while dealing with variables?

    Answer:

    Use variables to store values and print later. if var keyword is not used then value is stored in the variable and printed. Wheras if var keyword is used then value is stored but not printed. You can use both variables later.

    View
  • 3.

    What is REPL in context of Node?

    Answer:

    REPL stands for Read Eval Print Loop and it represents a computer environment like a window console or unix/linux shell where a command is entered and system responds with an output. Node.js or Node comes bundled with a REPL environment. It performs the following desired tasks.

    • Read - Reads user's input, parse the input into JavaScript data-structure and stores in memory.

    • Eval - Takes and evaluates the data structure

    • Print - Prints the result

    • Loop - Loops the above command until user press ctrl-c twice.

    View
  • 4.

    Is Node a single threaded application?

    Answer:

    Yes! Node uses a single threaded model with event looping.

    View
  • 5.

    What is ‘Callback’ in node.js?

    Answer:

    Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don’t want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.

    View
  • 6.

    Mention the framework most commonly used in node.js?

    Answer:

    “Express” is the most common framework used in node.js

    View
  • 7.

    What is the command that is used in node.js to import external libraries?

    Answer:

    Command “require” is used for importing external libraries, for example, “var http=require (“http”)”.  This will load the http library and the single exported object through the http variable.

    View
  • 8.

    What does it mean “non-blocking” in node.js?

    Answer:

    In node.js “non-blocking” means that its IO is non-blocking.  Node uses “libuv” to handle its IO in a platform-agnostic way. On windows, it uses completion ports for unix it uses epoll or kqueue etc. So, it makes a non-blocking request and upon a request, it queues it within the event loop which call the JavaScript ‘callback’ on the main JavaScript thread.

    View
  • 9.

    What are the Challenges with Node.js ?

    Answer:

    Emphasizing on the technical side, it’s a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.

    View
  • 10.

    What is the difference between Node.js vs Ajax?

    Answer:

    The difference between Node.js and Ajax is that, Ajax (short for Asynchronous Javascript and XML) is a client side technology, often used for updating the contents of the page without refreshing it. While,Node.js is Server Side Javascript, used for developing server software. Node.js does not execute in the browser but by the server.

    View
  • 11.

    How Node.js overcomes the problem of blocking of I/O operations?

    Answer:

    Node.js solves this problem by putting the event based model at its core, using an event loop instead of threads.

    View
  • 12.

    What are the pros and cons of Node.js?

    Answer:

    Pros:

    a) If your application does not have any CPU intensive computation, you can build it in Javascript top to bottom, even down to the database level if you use JSON storage object DB like MongoDB.

    b) Crawlers receive a full-rendered HTML response, which is far more SEO friendly rather than a single page application or a websockets app run on top of Node.js.

    Cons:

    a) Any intensive CPU computation will block node.js responsiveness, so a threaded platform is a better approach.
    b) Using relational database with Node.js is considered less favourable

    View
  • 13.

    Mention the steps by which you can async in Node.js?

    Answer:

    By following steps you can async Node.js

    a) First class functions

    b) Function composition

    c) Callback Counters

    d) Event loops

    View
  • 14.

    What is an event loop in Node.js ?

    Answer:

    To process and handle external events and to convert them into callback invocations an event loop is used. So, at I/O calls, node.js can switch from one request to another.

    View
  • 15.

    What are the two arguments that async.queue takes?

    Answer:

    The two arguments that async.queue takes

    a) Task function

    b) Concurrency value

    View
  • 16.

    Why node.js is quickly gaining attention from JAVA programmers?

    Answer:

    Node.js is quickly gaining attention as it is a loop based server for JavaScript. Node.js gives user the ability to write the JavaScript on the server, which has access to things like HTTP stack, file I/O, TCP and databases.

    View
  • 17.

    Using the event loop what are the tasks that should be done asynchronously?

    Answer:

    a) I/O operations

    b) Heavy computation

    c) Anything requiring blocking

    View
  • 18.

    Can you access DOM in node?

    Answer:

    No, you cannot access DOM in node.

    View
  • 19.

    Does node run on windows?

    Answer:

    Yes – it does. Download the MSI installer from http://nodejs.org/download/

    View
  • 20.

    Why Node.js is single threaded?

    Answer:

    For async processing, Node.js was created explicitly as an experiment. It is believed that more performance and scalability can be achieved by doing async processing on a single thread under typical web loads than the typical thread based implementation.

    View

© 2017 QuizBucket.org