A newer version of this documentation is available.

View Latest

Check out a sample web app

Couchbase Travel is a sample web application that demonstrates how to interact with the Couchbase query service via the Node.js SDK.

You can download the complete source code and then build and run the app. While the app runs, you can view the log of N1QL queries that it sends. The documentation for the travel app illustrates the data model and walks through the N1QL queries used to select flights.

The travel app is written in Node.js and incorporates the following frameworks:

The application allows users to find flights by entering airports and travel dates. For the airport entries, the app uses a N1QL query bound to an Angular typeahead directive to suggest airport names based on the first few letters entered.

If you want to try the sample app first, without having to build and run the sample code, take a look at the travel app hosted at http://try.couchbase.com. See Using the travel app for guidelines on how to use the travel app.

Building and running the travel app

Couchbase Server and the sample travel app must be running on the same machine. To build and run the sample travel app:

  1. Install Couchbase Server 4.0.

    You do not need to set up the cluster after installation. The sample application takes care of this for you. If you have a Couchbase instance already installed and configured you can use it (that is, you don’t need to reinstall Couchbase Server to try this app).

  2. Install node.js on the machine that is running Couchbase Server.

  3. Install the Couchbase Node.js SDK:

    $ npm install couchbase
  4. In a terminal window on the machine that is running Couchbase Server, enter the following commands to install the sample application:

    $ mkdir ~/try-cb
    $ git clone https://github.com/couchbaselabs/try-cb-nodejs.git ~/try-cb
    $ cd ~/try-cb
    $ sudo npm install node-gyp -g
    $ npm install

    The command sequence creates a new directory, clones the GitHub repository that contains the travel app, and installs dependencies.

  5. If you already have a configured instance of Couchbase Server, edit the config.json file in the root of the cloned repository and change the username and password fields to match the credentials you entered when you set up Couchbase Server.

  6. Enter the following command:

    $ node app.js

    By default, the application automatically provisions a cluster on the installed Couchbase instance. The provisioning process outputs messages to the terminal. Provisioning and starting the app can take up to two minutes to complete based on the speed of your environment. Upon completion, the app outputs a message with the app login URL. You’ll see messages similar to this one:

    Amys-MacBook-Pro-6:try-cb amy$ node app.js
     ⇒ AUTOPROVISION: INITIATED
        COUCHBASE INSTANCE: localhost:8091 LOCATE
        COUCHBASE INSTANCE BUCKET: travel-sample CHECK IF PROVISIONED
         COUCHBASE INSTANCE: localhost:8091 LOCATED
         COUCHBASE INSTANCE BUCKET COUNT: 4 LISTED BELOW
          COUCHBASE INSTANCE BUCKET: beer-sample
          COUCHBASE INSTANCE BUCKET: default
          COUCHBASE INSTANCE BUCKET: joey
          COUCHBASE INSTANCE BUCKET: travel-sample
          COUCHBASE INSTANCE EXISTS: travel-sample PROVISIONED
     ⇐ AUTOPROVISION: ALREADY PROVISIONED. MOVING ON
    LOGIN AT http://localhost:3000

The travel app runs in the terminal window, which you need to keep open. To stop using the app, terminate the process by typing control-C.

Using the travel app

  1. Open a browser and navigate to the login URL that was displayed when you started the app.

  2. Sign in to Couchbase Travel by providing your credentials: travel app login

  3. Find a flight: travel app screen

    In the Airport or City section, enter an airport code or city name in the From and To fields.

  4. In the Travel Dates section, select Leave and Return dates by using the date picker that pops up when you click the date fields.

  5. Click Find Flights.

    The app displays the available flights for the outbound and return legs of the trip.