These exercises and solutions supplement the developerWorks knowledge path "Node.js beyond the basics."
- Convert this simple node web application into Coffeescript:
var express = require('express'); var app = express.createServer(express.logger()); app.get('/', function(req, res) { res.send("Hello World!"); }); var port = process.env.PORT || 3000; app.listen(port, function() { console.log("listening on " + port); });
- You inherited some code, written in Coffeescript, but it doesn't compile. Fix it:
express = require 'express' app = express.createServer(express.logger()); app.get '/', (req, res) -> console.log "/ hit!" res.send "Hello World!" var port = process.env.PORT || 3000 app.listen port, -> console.log "listening on #{port}"
- Amazon's DynamoDB only supports string data types:
- True
- False
- DynamoDB supports indexing many different keys in a table:
- True
- False
- Why won't this Node program run? What's wrong with it?
var express = require('express'); var app = express.createServer(express.logger()); app.get('/', function(req, res) { res.send("Hello World!"); }); var port = process.env.PORT || 3000; app.listen(port, function() { console.log("listening on #{port}"); }); - Cake is:
- CoffeeScript's build tool
- Node library for working with DynamoDB
- Language inspired by Fortran that makes working with JavaScript easier
- Deploying your code to Heroku is done via:
- SCP
- FTP
- Git push
- Custom protocol
- DynamoDB's Scan API allows you to:
- Search on non-primary key fields
- Bulk upload images
- Create new Attributes in an Item
- With the Mocha testing framework, you can test both synchronous and asynchronous code:
- True
- False
- You can speed up a web app hosted on Heroku by adding more Dynos:
- True
- False
- What's wrong with the logic in this Mocha test written in CoffeeScript? Why does this test fail?
describe 'updates for a beer using DynamoDB API', -> before (done) -> update = {votes: {put : 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: {add : 1}, type : {put: 'IPA'}} dynode.updateItem 'beer_ratings', '60 Minute IPA', update, (err, resp) ->
Check your answers here.
-
Node.js beyond the basics: This knowledge path starts with Node.js basics and takes you beyond them to using Node and supporting technologies to build an application, test it, and deploy it on a platform-as-a service.
-
developerWorks Java technology zone: Find hundreds of articles about every aspect of Java programming.

Andrew Glover is a developer, author, speaker, and entrepreneur with a passion for behavior-driven development, Continuous Integration, and Agile software development. He is the founder of the easyb Behavior-Driven Development (BDD) framework and is the co-author of three books: Continuous Integration, Groovy in Action, and Java Testing Patterns. You can keep up with him at his blog and by following him on Twitter.



