O'Reilly logo

RESTful Web API Design with Node.js by Valentin Bojinov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing a NoSQL database solution

The asynchronous nature of Mongoose makes it bit difficult to test in a Nodeunit environment. Node.js provides means for handling such cases, but as we are developing a RESTful application, perhaps the easiest way for us would be to use the contact data service module in an express application and then use a third-party tool designed especially for testing RESTful services.

So, the first step is to create the following express application using our module:

var express = require('express') , http = require('http') , path = require('path') , bodyParser = require('body-parser') , logger = require('morgan') , methodOverride = require('method-override') , errorHandler = require('errorhandler') , mongoose = require('mongoose') ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required