This application uses the Cloudant NoSQL Database service to demonstrate the operations of Create, Read, Update and Delete into database using the Node.js runtime. Cloudant node module is used for these operations. They can alternatively be done with API calls which returns a JSON.
$cf api https://api.ng.bluemix.net
$cf login
$cf create-service cloudantNoSQLDB Lite <service-name>
$cf bs NodeJSCloudantSampleApp <service-name-as-in-previous-step>
applications:
- path: .
name: NodeJSCloudantSampleApp
host: <change_to_something_unique>
framework: node
memory:256M
instances: 1
services:
- <service-name>
The host you use will determinate your application url(e.g.
declared-services:
cloudant-nodejs:
label: cloudantNoSQLDB
plan: Shared
$cf start NodeJSCloudantSampleApp
And voila! Your very own instance of Cloudant NoSQL DB with NodeJSCloudantSampleApp is now running on Bluemix.
https://github.com/IBM-Bluemix/nodejs-cloudantdb-crud-example
cloudant_url = "<paste 'url' here>"
Comment out lines 20-28
/*
if(process.env.VCAP_SERVICES)
{
services = JSON.parse(process.env.VCAP_SERVICES);
if(services.cloudantNoSQLDB) //Check if cloudantNoSQLDB service is bound to your project
{
cloudant_url = services.cloudantNoSQLDB[0].credentials.url; //Get URL and other paramters
console.log("Name = " + services.cloudantNoSQLDB[0].name);
console.log("URL = " + services.cloudantNoSQLDB[0].credentials.url);
console.log("username = " + services.cloudantNoSQLDB[0].credentials.username);
console.log("password = " + services.cloudantNoSQLDB[0].credentials.password);
}
}
*/
npm install
node app.js
http://localhost:<port_number>
Paste this URL in the browser to open the application.
https://github.com/cloudant/nodejs-cloudant/blob/master/example/crud.js
https://www.ng.bluemix.net/docs/#services/Cloudant/index.html#Cloudant
To troubleshoot your Bluemix app the main useful source of information are the logs, to see them, run:
$ cf logs <application-name> --recent
This sample code is licensed under Apache 2.0. Full license text is available in LICENSE. This sample uses socket.io which is MIT license
See CONTRIBUTING.
Find more open source projects on the IBM Github Page