Node.js beyond the basics

Test your knowledge path progress

Return to article

  1. Convert this simple node web application into Coffeescript
    express = require 'express'
    
    app = express.createServer express.logger()
    
    app.get '/', (req, res) ->
    	res.send "Hello World!"
    
    port = process.env.PORT or 3000
    
    app.listen port, ->
    	console.log "listening on #{port}"
  2. You inherited some code, written in Coffeescript, but it doesn't compile. Fix it
    # issues are spacing in / method and var
    express = require 'express'
    
    app = express.createServer(express.logger());
    
    app.get '/', (req, res) ->
    	console.log "/ hit!"
    	res.send "Hello World!"
    
    port = process.env.PORT || 3000
    
    app.listen port, ->
    	  console.log "listening on #{port}"
  3. Amazon's DynamoDB only supports string data types
    1. True
    2. False
  4. DynamoDB supports indexing many different keys in a table
    1. True
    2. False
  5. Why won't this Node program run? What's wrong with it?

    JavaScript doesn't support string interpolation. Thus, this line: console.log("listening on #{port}"); must be changed to: console.log("listening on " + port);

  6. Cake is:
    1. CoffeeScript's build tool
    2. Node library for working with DynamoDB
    3. Language inspired by Fortran that makes working with JavaScript easier
  7. Deploying your code to Heroku is done via:
    1. SCP
    2. FTP
    3. Git push
    4. Custom protocol
  8. DynamoDB's Scan API allows you to:
    1. Search on non-primary key fields
    2. Bulk upload images
    3. Create new Attributes in an Item
  9. With the Mocha testing framework, you can test both synchronous and asynchronous code:
    1. True
    2. False
  10. You can speed up a web app hosted on Heroku by adding more Dynos:
    1. True
    2. False
  11. What's wrong with the logic in this Mocha test written in CoffeeScript? Why does this test fail?

    The fixtures are logically incorrect. The before will make the value of votes to 1. The test will fail and then the after fixture will add another 1. The fixtures should be reversed to:

    describe 'updates for a beer using DynamoDB API', ->
    	before (done) ->
    		update = {votes: {add : 1}, type: {put: 'IPA'}}
    		dynode.updateItem 'beer_ratings', '60 Minute IPA', update, (err, resp) ->
    			done(err)
    	it 'should support incrementing a value corresponding to a vote', (done) ->
    		dynode.getItem 'beer_ratings', '60 Minute IPA', (err, item, meta) ->
    			item.should.have.property 'votes'
    			item.votes.should.be.above 1
    			done(err)
    	after ->
    		update = {votes: {put : 1}, type : {put: 'IPA'}}
    		dynode.updateItem 'beer_ratings', '60 Minute IPA', update, (err, resp) ->

Return to article