How to use CouchDB in Sails.js - node.js

I want to create a web in node js with the using the "Sails.js" framework and "CouchDB" database. I have check its package and I found lots of package for that.
https://www.npmjs.com/search?q=couchdb
So any one can suggest which package I can used for my application and also want to know for this I need to create a custom adapter.
If there has no requirement of create a custom adapter, so can I use the sails module feature.

The most popular CouchDB adapter in JS :
PouchDB
nanoDB
They are both available on NPM.
PouchDB has a lot of features and his API is easy to use. It also supports a lot of return types (callbacks,promises, async/await). There's also a lot of plugins around PouchDB.
As for nanoDB, it has less features(since it`s minimalist) but it covers all the general features of CouchDB.
Note: nanoDB normal implementation is with callbacks(which can be very ugly). There is an implementation of nanoDB with promises here.

You can take a look also to this adapter sails-couchdb-orm, but it could be no longer maintained. If you plan deploying your project using IBM Bluemix, you should try using sails-cloudant-orm. Cloudant is based on Apache CouchDB.

Related

How to efficiently update the API when Swagger spec file is updated? (express, nodejs)

I'm trying to setup a nodejs-express boilerplate for my new project, and this time I want to try doc-driven flow. I've checked couples of packages like swagger-node, swaggerize-express ...etc. They all provide great functionalities.
However, I don't see anything that could support incremental scaffolding when the Swagger file is updated. That means when the spec changes I have to manually check the diff and manually add/modify the new specs. That doesn't sound cool.
Does anyone could share something that is more reasonable? Thanks!!!
Edit:
After trying some frameworks, I decided to use swagger-express-middleware. This framework offers a convenient way to automatically check routes/parameters for your service.
You can use tools like swagger-maven-plugin to incrementally rebuild your server code, which means reading from your api definition and updating/building code as necessary. There are SAAS products like SwaggerHub which enable this as well, by merging code and pushing to git.

Do I need Express or some other framework in order to make a Node site?

People keep mentioning Node as a back-end framework but it's actually a runtime. Does this mean I need to install a package like Express in order to actually create a website based on the Node runtime? Does Node come with its' own implementation of a back-end framework?
Looking at the Node docs most of this stuff has nothing to do with usual framework stuff like testing, migrations, MVC, or asset precompilation.
It is not required to use Express or a similar framework to develop web pages since you can just create a web server using Node's http module.
That being said, the additional functionality that a framework like Express would provide is something you should at least consider.

Is there a way to self-host mongoose databases?

I am getting started with writing an API for a project and the tutorial I am following suggests I sign up for a hosted solution. I think that is ridiculous. My project is simple and I do not feel the need to be locked in to a service. If it helps, I am using Express.
Mongoose is a node.js module (library) which is used to interact with a database, called MongoDB.
There are some websites like mongolab.com which offer plans for development for free, so you would jsut need to sign up and you will get a database without installink anything in your computer/server etc. This is why they say it is easier.
You can install MongoDB in your local computer to test (I think most of us have it) and use just that one for developing and testing.
To install MongoDB it all depends which Operating System you are using at the moment. But you can look up on google: "Install MongoDB MacOSX/Window/Ubuntu/etc.." and normally is just one simple command. To connect to it in your local you don't need a user or anything I guess.

Re-using backbone routes, models, and views on the node.js server

I am trying to build an application which both works as a SPA and as a normal application without re-writing any of the code as much as possible. My research has led to believe that this could be very possible using node + backbone (on both the server and client). I have found some resources on how to do this but nothing truly complete. Have anyone tried a full solution to re-using all the code?
The resources that I found:
Re-using backbone models on the server: http://blog.andyet.com/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
Re-using backbone views and layout manager on the server:
http://vimeo.com/46033641
I have also found some frameworks that achieve this such as (bones, derby, meteor), but I dont feel like using such a framework is the best solution since I still want to have full control over backbone and node.
What you are trying to implement is Resource-View-Presenter model. Please read this article completely http://blog.nodejitsu.com/scaling-isomorphic-javascript-code. It provides much needed insight for isomorphic code that can execute both on the client and the server. It also helped me understand various models and architectures.
What backbone.js uses is traditional MVC framework, which cannot work on both client and server without modifications. So if you want to stick to backbone.js you will face this disadvantage sooner or later. I tried backbone too and found no easy way to do that.
I tried looking for RVP frameworks on node.js, but it is still new. I would suggest you look into flatiron.js http://flatironjs.org/. It is based on Resource-View-Presenter model, the only one I could find for node.js. Some changes will be required to implement on both server/client, but it is not much. You will find it is similar to backbone.
Hope it helps you to find the right path.
I recently did some research on the field and found some interesting projects that are using the same backbone code on the client and server (nodejs).
Project 1
The first one was introduced by Keith Norma from Groupon. He managed to reuse backbone router + templates on the client and server.
App demo: https://github.com/keithnorm/SpainJS-Pipedream-Demo
Presentation at SpainJS talk: http://www.youtube.com/watch?v=jbn9c_yfuoM
Project 2
The second project is Rendr presented by Spike Brehm from Airbnb but not released yet to the public. It seems a bit more ambitious as it also trades backbone model and collections to the nodejs server. You can read more about it here: http://nerds.airbnb.com/weve-launched-our-first-nodejs-app-to-product
UPDATE: Rendr code has been released: https://github.com/airbnb/rendr
Project 3
There is another project that also allows to share backbone code between client and server: https://github.com/developmentseed/bones

NoSQL/MongoDB Style Query Engine in Node.js

I've built a static website generator which more or less converts markdown documents to html pages. Documents can have tags, which are useful for discovering related documents - and thus is the requirement for a query engine.
Right now I'm using MongoDB but as the application is coded in Node.js and due to the extreme lack of MongoDB support on Node.js hosts (so far no.de is the only one that I know of which supports mongodb), as well as a static website generator having absolutely no need for data persistence, I'd like to remove MongoDB and just keep the query engine.
Are there any MongoDB/NoSQL like query engines coded natively in Node.js/javascript? Or is there a better solution I haven't thought of yet... :S
Thanks guys.
Edit: If there is no such thing, who would like to build it with me? Post a comment if so :)
I'd check out JSONSelect which uses css selectors for querying js objects
Created my own in Coffee-Script for use on the Server-Side with Node.js and Client-Side with Web-Browsers.
It supports all the same queries as MongoDb. Find it here:
https://github.com/bevry/query-engine
RavenDB has a REST API and jQuery plugin available.
For example see http://andreasohlund.net/2011/02/19/accessing-ravendb-using-jsonp/
Take a look at libgit2 which is a C library for git and also the gitteh module for node.js This will give you a node wrapper around a git library - now you can have a local git repo that saves a versioned copy of your static files and serves it up via node.js. What more could you ask for? Plus push pull from github no problem - it knows the git protocols.
I haven't built this myself but happy to help if you want to do this

Resources