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:
- 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).
- 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.
- 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.
- 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 > email@example.com build /Users/todd/Express/try > node utils/provision.js PROVISION INITIALIZE SERVICES: 200 PROVISION RENAMING: 200 PROVISION INDEX STORAGE MODE: 200 PROVISION SERVICES: 200 PROVISION MEMORY: 200 PROVISION ADMIN USER: 200 PROVISION BUCKET: 202 LOADING ITEMS:100% of 31565 Items BUCKET: travel-sample LOADED. PROVISION FTS INDEX: 200 Cluster localhost:8091 provisioning complete. To login to couchbase: open a browser localhost:8091 To run the travel-sample application, run 'npm start'
- Now, and at any point in the future whenever you want to run the travel-sample application, just run the following command:
You will see a message like the following, telling you where to point your browser to use the application:
$ npm start
npm start > firstname.lastname@example.org 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
- Open a browser and navigate to the login URL that was displayed when you started the app.
- Sign in to Couchbase Travel by providing your credentials:
- Find a flight:
In the Airport or City section, enter an airport code or city name in the From and To fields.
- In the Travel Dates section, select Leave and Return dates by using the date picker that pops up when you click the date fields.
- Click Find Flights.
The app displays the available flights for the outbound and return legs of the trip.