NodeJS quiz questions

NodeJS interview questions

  • 1.

    Fs module provides both synchronous as well as asynchronous methods.

    1. True

    2. False

    Answer
  • 2.

    How can we create chainable route handlers for a route path in ExpressJS app?

    1. Using app.route()

    2. Using app.router()

    3. Using app.routing()

    Answer
  • 3.

    The methods on the response object (res) in the following table can send a response to the client, and terminate the request-response cycle. If none of these methods are called from a route handler, the client request__________

    Method Description
    res.download() Prompt a file to be downloaded.
    res.end() End the response process.
    res.json() Send a JSON response.
    res.jsonp() Send a JSON response with JSONP support.
    res.redirect() Redirect a request.
    res.render() Render a view template.
    res.send() Send a response of various types.
    res.sendFile() Send a file as an octet stream.
    res.sendStatus() Set the response status code and send its string representation as the response body.
    1. will be left hanging

    2. will get an internal server error (500)

    3. will get an service unavailable error (503)

    Answer
  • 4.

    Is the code below valid?

    var cb0 = function (req, res, next) {
      console.log('CB0')
      next()
    }
    var cb1 = function (req, res, next) {
      console.log('CB1')
      next()
    }
    app.get('/example/d', [cb0, cb1], function (req, res, next) {
      console.log('the response will be sent by the next function ...')
      next()
    }, function (req, res) {
      res.send('Hello from D!')
    })
    1. Yes

    2. No

    Answer
  • 5.

    Is the below code valid?

    var cb0 = function (req, res, next) {
      console.log('CB0')
      next()
    }
    var cb1 = function (req, res, next) {
      console.log('CB1')
      next()
    }
    var cb2 = function (req, res) {
      res.send('Hello from C!')
    }
    app.get('/example/c', [cb0, cb1, cb2])
    1. Yes

    2. No

    Answer
  • 6.

    How many number of callback functions can be attached to handle a request?

    1. Just one

    2. Unlimited

    Answer
  • 7.

    Select all valid rout parameter formats

    1. /users/:userId/books/:bookId

    2. /flights/:from-:to

    3. /books/!:from-:to

    Answer
  • 8.

    Where is captured values are populated regarding route parameters?

    1. req.params object

    2. app.locals object

    3. req.data object

    4. None of above

    Answer
  • 9.

    Route paths, in combination with a request method, define the endpoints at which requests can be made.

    Which of following are valid form of route path?

    1. strings

    2. string patterns

    3. regular expressions

    4. All of above

    Answer
  • 10.

    What should you do in your code to improve your application’s performance?

    (Multiple choices)

    1. Use gzip compression

    2. Don’t use synchronous functions

    3. Do logging correctly

    4. Handle exceptions properly

    Answer
  • 11.

    In ExpressJS, the method app.all(path, callback [, callback ...]) can accept all HTTP methods

    1. True

    2. False

    Answer
  • 12.

    How to store local variables that can be access within the application?

    1. Ussing app.locals

    2. Using app.storage

    3. Using database

    4. Config file

    Answer
  • 13.

    If an EventEmitter does not have at least one listener registered for the 'error' event, and an 'error' event is emitted, the error is thrown, a stack trace is printed, and the Node.js process ____.

    1. continues

    2. exits

    Answer
  • 14.

    Which method can be used to handle an event just only one time?

    1. eventEmitter.on()

    2. eventEmitter.once()

    3. Another one

    Answer
  • 15.

    How many listenners can be attached to an event in NodeJS?

    1. Unlimited

    2. 10

    Answer
  • 16.

    By default EventEmitters will print a warning if more than ______ listeners are added for a particular event

    1. 10

    2. 20

    3. 30

    4. 100

    Answer
  • 17.

    Which methods can be use to switch listener functions asynchronous mode:

    1. setImmediate()

    2. process.nextTick()

    3. Both of them

    Answer
  • 18.

    When the EventEmitter object emits an event, all of the functions attached to that specific event are called _______. Any values returned by the called listeners are ignored and will be discarded.

    1. synchronously

    2. asynchronously

    Answer
  • 19.

    All objects that emit events are instances of the EventEmitter class

    1. True

    2. False

    Answer
  • 20.

    What are Nodejs characteristics?

    1. Event-driven,

    2. Non-blocking I/O

    3. Both of them

    Answer

© 2017 QuizBucket.org