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.
Couchbase Server and the sample travel app must be running on the same machine. To build and run the sample travel app:
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).
Install node.js on the machine that is running Couchbase Server.
Install the Couchbase Node.js SDK:
$ npm install couchbase
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.
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
passwordfields to match the credentials you entered when you set up Couchbase Server.
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
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.