Installing the Required Modules
Express framework is required to run this app, to install the express framework, open the command prompt/shell and type the below command. The “–g” option simply means the module will be installed globally so that for each project we don’t need to install express separately.
npm install –g express
npm install nano (To install nano module)
Follow the Below Steps to Setup Our Project
After installing nodejs, execute the following commands in order-
npm install express –g
npm install jade –g
express couchNano
cd couchNano
npm install nano
npm link express
npm link jade
node app.js //to run the app
And go to browser (any browser) and type below in address bar http://localhost:3000. And press enter if you get the “welcome to express” page you have success created the basic structure required for this app.
Change or create the createdb.js,index.jade,layout.jade,app.js.You can see the detail code at
https://hub.jazz.net/project/blackwhites/cloudant/overview.
In the app.js there is a piece of code you might need to config on your side .
var nano = require('nano')('https://username:password@yourdomain.cloudant.com:443');
/*Specify the database to use, so that we don't have to specify everytime*/
var db = nano.use('yourdb')
You need to enter the correct username,password and your cloudant host address.Also you need to make sure you have create your db before in your hosted cloudant doamin.
After finish your code,you need to create a package.json file to add your node.js dependency.
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.4",
"jade": "*",
"nano": "*.*"
}
}
Finish all the setting,you can open node.js command in your project folder to use npm install command to install node.js module.After that use node app.js to run your sample.
Open the browser and use localhost:3000 to visit,Here I add Contacts as the sample
You can see the successful info after you submit the contacts info.
You can check the data in the your online Cloudant db.
---
applications:
- name: cludanttest
memory: 256M
instances: 1
host: cludanttest
domain:ng.bluemix.net
path: .
command: node app.js
Hi, its nice tutorial.
ReplyDeleteBut how can I update/ edit the json?
bytheway, where I can get createdb.js,index.jade,layout.jade,app.js code?
Deletethe link you gived is not valid anymore --> https://hub.jazz.net/project/blackwhites/cloudant/overview