A newer version of this documentation is available.

View Latest

Couchbase Travel 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 type ahead 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

To start with, it’s easiest if you run Couchbase Server and the travel sample app on the same machine. It’s not required to run your development environment this way it’s just easier to start a development environment with components running locally. Advanced "MDS" configurations are supported. To build and run the sample travel app follow these steps:

  1. Install Couchbase Server 4.5.

    You do not need to provision the cluster "manually" after installation. The sample application can take care of this for you. If you have a Couchbase instance already installed and configured, you can just use the application (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. This application uses recent JavaScript features (ES6) for provisioning (fat arrow functions, promises, classes). Please make sure the version of node.js you are installing is 4.0.0 or higher.

  3. 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
    $ npm install

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

  4. If you already have a configured instance of Couchbase Server, edit the config.batinc 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.

  5. To provision the travel-sample application and setup a cluster from the instance of Couchbase Server that you downloaded and installed, enter the following command from the ~/try-cb directory:

    $ npm run build

    Using a script defined in the package.json file under the "build" section for the application, npm 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 only need to run 'npm run build' once, and if it’s run again it will not re-provision the Couchbase instance. You’ll see messages similar to this one:

    $ npm run build
    > try-cb@0.1.0 build /Users/todd/Express/try
    > node utils/provision.js
        LOADING ITEMS:100%  of 31565 Items
        BUCKET: travel-sample LOADED.
    Cluster localhost:8091 provisioning complete.
       To login to couchbase: open a browser localhost:8091
       To run the travel-sample application, run 'npm start'
  6. Now, and at any point in the future whenever you want to run the travel-sample application, just run the following command:

    $ npm start

    You will see a message like the following, telling you where to point your browser to use the application:

    npm start
    > try-cb@0.1.0 start /Users/todd/Express/try
    > node app.js
    ENVIRONMENT: READY--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 Ctrl-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.