Node.js install cloudant module - node.js

Hi I am making a Cordova app for iOS and Android. I am trying to use the cloudant module https://github.com/cloudant/nodejs-cloudant to access my cloudant couchDB, but for the life of me, I cannot figure out the issue I am having while installing it. Using linux, I executed npm install --save cloudant at the root of my Cordova project folder. When using var Cloudant = cordova.require('cloudant'); in my code, I get the error Uncaught module cloudant not found from within my cordova.js file as it tries to load the module. Also when I run $ node -e 'require("cloudant"); console.log("Cloudant works");' in my shell, I receive a terminal output stating "Cloudant works". I cannot seem to figure out what the issue is, and have tried many different things. Any help is extremely appreciated, as I am at my witts end at this point. Thanks.

As #Parth says, 'nodejs-cloudant' is a Node.js/npm module. To access Cloudant from within your Cordova application you will need client side code to interact with Cloudant's HTTP API.
You could use jQuery's Ajax functions to make HTTP requests to Cloudant or you can use PouchDB as a client-side library e.g:
<script src="pouchdb-3.4.0.min.js"></script>
<script>
var db = new PouchDB("https://myusername:mypassword#myaccount.cloudant.com/mydb";
</script>
Both solutions require you to enable CORS on your Cloudant account.

'nodejs-cloudant' is an npm module and not a cordova module. you just need to write
var Cloudant = require('cloudant'); That should solve the problem.

Try with this:
var Cloudant = require('cloudant');

Instead of importing cloudant directly, try using cradle or nano for accessing cloudant
'DB.const nano = require('nano')('//cloudant api link//');'
This works
https://www.npmjs.com/package/nano#dbinsertdoc-params-callback
https://www.npmjs.com/package/cradle

Related

How to create simple webhooks for asana

I'm new to asana API and need help in creating webhooks to track activities in asana. a simple example using NodeJS would be fine. thank you.
Check this out: https://github.com/Asana/node-asana
A JavaScript client (for both Node and browser) for the Asana API v1.0.
Install with npm:
npm install asana --save
Browser
Include the latest release directly from GitHub.
<script src="https://github.com/Asana/node-asana/releases/download/<LATEST_RELEASE>/asana-min.js"></script>
OR
Download the latest distribution in releases.
Make sure to serve it from your webserver.
Include it on the client from a SCRIPT tag.
Usage
To do anything, you'll need always an instance of an Asana.Client configured with your preferred authentication method and other options.
The most minimal example would be as follows:
const asana = require('asana');
const client = asana.Client.create().useAccessToken('my_access_token');
client.users.me().then(function(me) {
console.log(me);
});

How to sync react native app with express app?

I am using react native android app for recording calls.Once the call get recorded, it should be uploaded to serer(express js and mysql) with call details.Suppose the app is in offline the file should uploaded to server whenever the app comes to online.How should i acheive this.
NOTE: All the above mentioned process should be run in background.
I found some solutions like pouchdb. For react native (pouchdb-react-native) npm and for express js (express-pouchdb) using this npm can i achive the sync? and how?
It is possible - using PouchDb server and LevelUp - to sync PouchDb with different backend databases. See this answer for details and the Nolan Lawson article on LevelUp.

All requests via Proxy in Node-Webkit

Is there a way to force Node-webkit to use proxied settings for all requests ? I know there is an API solution using setProxyConfig() but this doesn't work with authenticated proxy, the prompt shows up to login but crash when submitted...
So I tried to use node request module, and it works fine :
var request=require('request');
var proxy = request.defaults({'proxy':'http://login:pwd#proxy:port'});
But now my problem is to tell node-webkit to use this for each request.
Any solutions ?
I'm quite new using node and node-webkit so maybe there is a better way to do that.
Thanks a lot !
You may try
process.env.http_proxy = 'http://login:pwd#proxy:port'
It will work with request lib, also should impact other requests from node-webkit (assets, ajax)
But may be other libraries don't use environment proxy settings. If that doesn't work you can try https://www.npmjs.com/package/global-tunnel
Not sure if this is solved, but i came up with a simple solution:
i wrote a simple wrapper for the request library
https://gist.github.com/jodevsa/7dd9662b8244359fa0d7626ae7c9bd69
all you have to do is ,
Head to $PROJECT_DIR/node_modules/request/
Rename index.js to core.js
Create a new file called index.js
Copy code content from the above gist link to index.js
Change proxyLoc value to you'r preferred proxy
If you decided to disable proxy , just change value of ON variable to false inside index.js
Cheers :D

Import only once a plugin in hapijs and use it everywhere

I should use a plugin named hapi-mongoose-db-connector into my hapijs application. In the repository page the developers suggest the ways you can import correctly it. It says that the following way is the bad way:
# from the server
mongoose = server.pack.plugins['hapi-mongoose-db-connector'].mongoose
# or from a plugin
mongoose = plugin.plugins['hapi-mongoose-db-connector'].mongoose
and discourages using it. Instead he recommends to do in the following way:
You do nothing and just require mongoose in your plugins. As npm
requires are singletons (the code is loaded only once this works very
well)
but he doesn't show any examples. At this point I'm not pretty sure how to use it. I wouldn't call in every js files mongoose. I would call it once in my application somewhere and in my js files where I create models for the database, use it. Do you know any best practices in those cases?
Actually, first one is the hapi way doing this kind of thing.
But as the mongoose module is a singleton, that plugin just require mongoose and initialize it [1] after load that plugin into hapi, you can use mongoose in any file;
var mongoose = require("mongoose");

Node.js + Angular = Uncaught ReferenceError: require is not defined

I'm creating an Express.js API on a Node.js server. The API is used to access data stored on the server. I also keep a log of who's accessing the API in a database.
I'm trying to create an admin section that will use Angular.js to display the admin access logs neatly. I used the Angular Express Bootstrap seed to start my project:
https://github.com/jimakker/angular-express-bootstrap-seed/
My problem is that I need the controllers.js to access node modules but it doesn't seem to know that node exists. Here is my error:
controller.js
var mongo = require('mongodb');
[Uncaught ReferenceError: require is not defined]
How can I use node modules in Angular.js files?
Node is a server side technology, you would not typically use your node modules on the browser with Angular.js. However, if you want commonjs require functionality in the browser see: https://github.com/substack/node-browserify.
Ofcourse, a browser can't talk to mongodb directly which is why you need an API in the first place, angular would communicate with your API using HTTP.
Angular.js makes an $http call to Node.js which requires and talks to the mongodb.

Resources