@@ -56,17 +56,19 @@ errors:
5656
5757### Getting Started
5858
59- Initialize your Cloudant connection by supplying your * account * and * password * .
59+ Initialize your Cloudant connection by supplying your ` url ` and credentials .
6060
6161~~~ js
6262// Load the Cloudant library.
6363var Cloudant = require (' @cloudant/cloudant' );
6464
65- var me = ' nodejs' ; // Set this to your own account.
65+ // Get account details from environment variables
66+ var url = process .env .cloudant_url ;
67+ var username = process .env .cloudant_username ;
6668var password = process .env .cloudant_password ;
6769
68- // Initialize the library with my account .
69- var cloudant = Cloudant ({ account : me , password: password });
70+ // Initialize the library with url and credentials .
71+ var cloudant = Cloudant ({ url : url, username : username , password: password });
7072~~~
7173
7274If you omit the ` password ` in your configuration then you get an "anonymous"
@@ -79,7 +81,8 @@ NPM, then create a `.env` file with your Cloudant credentials. For example:
7981~~~
8082npm install dotenv # Install ./node_modules/dotenv
8183echo "/.env" >> .gitignore # Do not track .env in the revision history
82- echo "cloudant_username=myaccount" > .env # Replace myaccount with your account name
84+ echo "cloudant_url=https://myaccountid.cloudantnosqldb.appdomain.cloud " > .env # Replace myaccountid with your account name
85+ echo "cloudant_username=myuser" > .env # Replace myuser with your username
8386echo "cloudant_password='secret'" >> .env # Replace secret with your password
8487~~~
8588
@@ -92,9 +95,10 @@ require('dotenv').load();
9295var Cloudant = require (' @cloudant/cloudant' );
9396
9497// Initialize Cloudant with settings from .env
95- var username = process .env .cloudant_username || " nodejs" ;
98+ var url = process .env .cloudant_url ;
99+ var username = process .env .cloudant_username ;
96100var password = process .env .cloudant_password ;
97- var cloudant = Cloudant ({ account : username, password: password });
101+ var cloudant = Cloudant ({ url : url, username : username, password: password });
98102
99103// Using the async/await style.
100104
@@ -165,7 +169,7 @@ var Cloudant = require('@cloudant/cloudant');
165169var cloudant = Cloudant (" http://MYUSERNAME:MYPASSWORD@localhost:5984" );
166170~~~
167171
168- ** Note** : It is preferred to pass credentials using the ` account ` / ` username ` and
172+ ** Note** : It is preferred to pass credentials using the ` url ` and ` username ` and
169173` password ` configuration options rather than as part of the URL. However, if you
170174choose to pass credentials in the user information subcomponent of the URL then
171175they must be [ percent encoded] ( https://tools.ietf.org/html/rfc3986#section-3.2.1 ) .
@@ -192,16 +196,20 @@ var cloudant = Cloudant({ username:'myusername', password:'mypassword', url:'htt
192196
193197##### 2.1. Connecting to Cloudant
194198
195- You can just pass your account name and password:
199+ You can just pass your account, username and password:
196200
197201~~~ js
198202var Cloudant = require (' @cloudant/cloudant' );
199- var cloudant = Cloudant ({ account: me, password: password });
203+ var cloudant = Cloudant ({ account: acct, username : me, password: password });
200204~~~
201205
202- By default, when you connect to your cloudant account (i.e. "me.cloudant.com"),
203- you authenticate as the account owner (i.e. "me"). However, you can use Cloudant
204- with any username and password. Just provide an additional "username" option
206+ _ Notes:_
207+ * If you use the ` account ` option then the account is appended with ` .cloudant.com ` .
208+ The ` url ` option is preferred as ` cloudant.com ` is no longer the preferred domain.
209+ * If you omit ` username ` then the ` account ` will be used as the ` username ` . This is not
210+ recommended as the default username for newer Cloudant accounts does not match the account name.
211+
212+ You can use Cloudant with an alternative username and password. Just provide an additional ` username ` option
205213when you initialize Cloudant. This will connect to your account, but using the
206214username as the authenticated user. (And of course, use the appropriate
207215password.)
@@ -254,10 +262,11 @@ callback parameter:
254262
255263~~~ js
256264var Cloudant = require (' @cloudant/cloudant' );
257- var me = ' nodejs' ; // Replace with your account.
265+ var url = process .env .cloudant_url ;
266+ var username = process .env .cloudant_username ;
258267var password = process .env .cloudant_password ;
259268
260- Cloudant ({ account : me , password: password }, function (err , cloudant , pong ) {
269+ Cloudant ({ url : url, username : username , password: password }, function (err , cloudant , pong ) {
261270 if (err) {
262271 return console .log (' Failed to initialize Cloudant: ' + err .message );
263272 }
@@ -413,7 +422,7 @@ var cloudant = Cloudant({ url: myurl, maxAttempt: 5, plugins: [ { iamauth: { iam
413422
414423 For example:
415424 ` ` ` js
416- var cloudant
= Cloudant ({ url
: ' https://user:[email protected] ' , plugins
: ' cookieauth' });
425+ var cloudant = Cloudant ({ url: myurl, username : username, password : password , plugins: ' cookieauth' });
417426 ` ` `
418427
419428 The plugin will transparently call ` POST / _session` to exchange your
@@ -428,7 +437,7 @@ var cloudant = Cloudant({ url: myurl, maxAttempt: 5, plugins: [ { iamauth: { iam
428437
429438 You can turn off automatically refreshing cookie with the following configuration:
430439 ` ` ` js
431- var cloudant
= Cloudant ({ url
: ' https://user:[email protected] ' , plugins
: [ { cookieauth
: { autoRenew
: false } } ] });
440+ var cloudant = Cloudant ({ url: myurl, username : username, password : password , plugins: [ { cookieauth: { autoRenew: false } } ] });
432441 ` ` `
433442
4344432. ` iamauth`
@@ -442,7 +451,7 @@ var cloudant = Cloudant({ url: myurl, maxAttempt: 5, plugins: [ { iamauth: { iam
442451
443452 For example:
444453 ` ` ` js
445- var cloudant = Cloudant ({ url: ' https://examples.cloudant.com ' , plugins: { iamauth: { iamApiKey: ' xxxxxxxxxx' } } });
454+ var cloudant = Cloudant ({ url: myurl , plugins: { iamauth: { iamApiKey: ' xxxxxxxxxx' } } });
446455 ` ` `
447456
448457 The production IAM token service at https://iam.cloud.ibm.com/identity/token is
@@ -464,7 +473,7 @@ var cloudant = Cloudant({ url: myurl, maxAttempt: 5, plugins: [ { iamauth: { iam
464473
465474 You can turn off automatically refreshing token with the following configuration:
466475 ` ` ` js
467- var cloudant
= Cloudant ({ url
: ' https://user:[email protected] ' , plugins
: [ { iamauth
: { iamApiKey
: ' xxxxxxxxxx' , autoRenew
: false } } ] });
476+ var cloudant = Cloudant ({ url: myurl , plugins: [ { iamauth: { iamApiKey: ' xxxxxxxxxx' , autoRenew: false } } ] });
468477 ` ` `
469478
4704793. ` retry`
@@ -559,9 +568,10 @@ others access to your data, without giving them the keys to the castle.
559568
560569~~~ js
561570var Cloudant = require('@cloudant/cloudant');
562- var me = 'nodejs'; // Replace with your account.
571+ var url = process.env.cloudant_url;
572+ var username = process.env.cloudant_username;
563573var password = process.env.cloudant_password;
564- var cloudant = Cloudant({ account:me , password:password });
574+ var cloudant = Cloudant({ url: url, username: username , password:password });
565575
566576cloudant.generate_api_key(function(err, api) {
567577 if (err) {
@@ -629,7 +639,7 @@ appropriate password associated with the Cloudant API key.)
629639
630640~~~ js
631641var Cloudant = require('@cloudant/cloudant');
632- var cloudant = Cloudant({ account:"me" , key:api.key, password:api.password });
642+ var cloudant = Cloudant({ url: url , key:api.key, password:api.password });
633643~~~
634644
635645## CORS
@@ -1183,15 +1193,16 @@ that credentials are also logged.
11831193
11841194### Advanced Configuration
11851195
1186- Besides the account and password options, you can add an optional
1196+ Besides the ` url ` , ` username ` and ` password` options, you can add an optional
11871197` requestDefaults` value, which will initialize Request (the underlying HTTP
11881198library) as you need it.
11891199
11901200~~~ js
11911201
11921202// Use an HTTP proxy to connect to Cloudant.
11931203var options =
1194- { "account" : "my_account"
1204+ { "url" : "https://myaccountid.cloudantnosqldb.appdomain.cloud"
1205+ , "username" : "myuser"
11951206 , "password" : "secret"
11961207 , "requestDefaults": { "proxy": "http://localhost:8080" }
11971208 }
@@ -1228,7 +1239,7 @@ var myagent = new protocol.Agent({
12281239 keepAliveMsecs: 30000,
12291240 maxSockets: 50
12301241});
1231- var cloudant = require('@cloudant/cloudant')({ account:"me ", password:"secret", requestDefaults: { agent: myagent } });
1242+ var cloudant = require('@cloudant/cloudant')({ url: "https://myaccountid.cloudantnosqldb.appdomain.cloud", username: "myuser ", password:"secret", requestDefaults: { agent: myagent } });
12321243// Using Cloudant with myagent...
12331244~~~
12341245
0 commit comments