Skip to content

Instantly share code, notes, and snippets.

@VidyasagarMSC
Last active May 23, 2016 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VidyasagarMSC/41e2e4da38cf28695511dd351ac0dcf6 to your computer and use it in GitHub Desktop.
Save VidyasagarMSC/41e2e4da38cf28695511dd351ac0dcf6 to your computer and use it in GitHub Desktop.
Connect to Cloudant from NodeJS running locally - For Test Purpose only

Prereqs

npm install dotenv 

Cloudant (DB)

Before querying the cloudant db, Create a cloudant DB and follow the steps below, create a .env file with your Cloudant credentials in the root directory.

 cloudant_username=myaccount # Replace myaccount with your account name
 cloudant_password='secret'  # Replace secret with your password

or on a terminal

 echo "/.env"                       >> .gitignore   # Do not track .env in the revision history
 echo "cloudant_username=myaccount" >  .env         # Replace myaccount with your account name
 echo "cloudant_password='secret'"  >> .env         # Replace secret with your password

Credentials in app.js

  require('dotenv').load();

 // Load the Cloudant library.
 var Cloudant = require('cloudant');

  var username = process.env.cloudant_username;
  var password = process.env.cloudant_password;

  // Initialize the library 
  var cloudant = Cloudant({
      account: username,
      password: password
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment