Framework + database for node.js - javascript

I'm used to developped on ruby mainly using RoR and deploying on heroku. I'd like to find out if a similar environment exists for node.js. I saw nodester.com (I'm still waiting for my coupon) but it seems there is no underlying database. Would you recommand a specific DB to work with node.js ?
Also, is there a kind of framework like RoR that could provide ORM capabilities (like ActiveRecord) ?

I started work on ActiveRecord implementation of MySQL for NodeJS on GitHub a while ago. It uses node-mysql module and the interface is similar to ActiveRecord class of CodeIgniter (a PHP framework).

Would you recommand a specific DB to
work with node.js ?
MongoDB or Redis, but it depends on your use case.
Also, is there a kind of framework
like RoR that could provide ORM
capabilities (like ActiveRecord) ?
Try to look at Express and mongoose.
Also check out a list of node.js modules.

Being that node is supported by Joyent (and some of the primary developers are employed by Joyent), you might want to look to them for hosting options: https://no.de/
Express is the primary framework in the land of node right now, but I'm not sure that ActiveRecord and Mongo are the happiest of pairs, you might want to look at MySQL options for node at that point. Something like noblerecord might work for you: https://github.com/noblesamurai/noblerecord

Check this:
Web application framework partial.js:
https://github.com/petersirka/partial.js
Async web framework
Simple view system
Simple routing
Supports simple CouchDB provider
Supports simple ORM (via HTTP-RDBMS)
https://github.com/petersirka/http-rdbms/

Related

Is there a good MSSQL / SQL Server adapter for sails.js?

I want to preface this with saying that I really like sails.js for a simple MVC framework, but feel that it lacks in its documentation and api reference.
I searched all over to try and find any information on a good mssql (SQL server) adapter for Sails.js, but cannot find one. I am hoping someone has come across one, and could recommend it. I also looked into building a custom adapter, but found the documentation to not be helpful. Any help on this topic would be greatly appreciated. Thank you.
We don't currently have a MS SQL Server adapter but it's something I'd love to add. There is a basic definition of the various interfaces and how adapters are created at: API Adapter Interface.
If anyone would like to tackle this you can use the Sails MySQL Adapter or the Sails PostgreSQL Adapter as examples.
I don't have access to a MS SQL Server to build one out but there is an Integration Test library I use to build out adapters that support the CRUD interface: Waterline Adapter Tests.
I have recently started building a sails adapter for MSSQL based on the node-sqlserver module.
It isn't finished yet but I have finished the main parts of the adapter and it still needs testing, but there is enough there to get going.
It can be found at https://github.com/swelham/sails-mssql
There is now: https://github.com/cnect/sails-sqlserver
Complete with sails 0.10 associations support, and fully unit tested against the Waterline spec:
Technically since Sails is base on express.js you could use custom express middleware to specify the use of your an adapter that has already been created.
The first one is the top rated adapter
checkout https://nodejsmodules.org/tags/mysql
Otherwise you can just use the waterline ORM and the MySQL adapter that is provided for sails.js
https://github.com/balderdashy/sails-mysql
For documentation on how to use waterline models checkout the 0.9x docuemntation
http://sailsjs.org/#!documentation/models
sails-mssql is working fine for me on 0.10.x, here's a gist of how to configure it, using sails-mssql 0.10.x
https://gist.github.com/hybrisCole/868f979d8d129247a2da
my package.json has this:
"sails-mssql": "git://github.com/jaredfromsubway/sails-mssql.git#master",
Sails-sql is currently the latest adapter for MySQL/MSSQL (eventually PostgreSQL as well). It's currently safe, fine-tuned, and upgraded for use in production with MySQL and MSSQL. Most developments are primarily pending for PostgreSQL at the moment.
Another current option is https://www.npmjs.com/package/sails-mssql (https://github.com/intel/sails-mssql).

Integration of Node.js and Backbone.js

I have done considerable reading on both Node.js and Backbone.js; I've read some tutorials and done the relevant courses on Code School. I feel that I've got a pretty good idea of the functions that each technology serves in the context of a web application.
My problem is that I don't really know how to integrate the two technologies and use them in tandem. I would really appreciate if someone could point me to a resource which goes through the entire development of an application using Node, MongoDB, and Backbone together.
Many thanks
This is a good tutorial that shows how to setup that entire stack.
http://backbonetutorials.com/nodejs-restify-mongodb-mongoose/
In short...
Node.js
You can use a library like restify to provide a restful API for your client-side Backbone application. It can also serve your static assets for your Backbone application. The example uses restify, but could be accomplished with other libraries like express.
Mongoose
Mongoose is a javascript abstraction layer for MongoDB. This provides an easy way to interact with MongoDB from Node.js.
Backbone
Your Backbone application can utilize your restify node.js backend to handle the model synchronization. You should have plenty of control to setup the routes via restify in a way that makes Backbone happy.
This ebook could be useful (it's on Backbone, but uses Node for the backend):
http://addyosmani.github.io/backbone-fundamentals/
You also may want to look at this book:
http://www.amazon.com/Building-Node-Applications-MongoDB-Backbone/dp/1449337392
There is also Node Cellar Source.
There is not much explanation about the code, but the app is simple enough to get started and understand the basics layouts of node / backbone
It is, i think, just between an 'Hello World' code and a full app.
I use for ap in backbone yeoman https://github.com/yeoman/generator-backbone and you use it with node.js too
create rest api: http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/
code backbone on the client: http://coenraets.org/blog/2012/10/nodecellar-sample-application-with-backbone-js-twitter-bootstrap-node-js-express-and-mongodb/
the backbonetutorials.com restify one is out of date. It's best to use express, especially if you plan to do any authorization. It's also more widely used
This is a comprehensive tutorial on rolling your own blog with Nodejs, Mongodb and expressjs
http://howtonode.org/express-mongodb
It's old but with a little effort you can get it to work and learn at the same time
I have found this to be the most up to date material on using Backbone.js with node
http://amzn.to/1DygKlJ

Questions about node.js

I've been trying to do some research on node.js and Mongodb and have a few things that need clarifying.
I'm trying to query Mongodb from the web and want to use JavaScript because I'm familiar with the language, plus it makes sense because that's what Mongodb uses in the command line interface.
It seems that I'll have to use node.js to query mongo from the web, but what I can't find info on is a way to tell my node.js server what I want to query, from the web.
If someone can point me in the proper direction ( reading material, how to, examples) that would be awesome.
Here's some articles I used...
http://css.dzone.com/articles/nodejs-and-mongodb-beginner%E2%80%99s-0
http://srirangan.net/2012-02-node-js-and-mongodb-getting-started-with-mongojs
http://mattkopala.com/blog/2012/02/12/getting-started-with-nodejs/
I found Mongoose to be the best Node.js MongoDB library (the creator of Mongoose actually now works for 10gen, the company behind MongoDB).
Besides a lot of good examples on the official Mongoose website, you can find lots of other resources:
http://pixelhandler.com/blog/2012/02/09/develop-a-restful-api-using-node-js-with-express-and-mongoose/
http://backbonetutorials.com/nodejs-restify-mongodb-mongoose/
http://dailyjs.com/web-app.html (how to build an app from the start, multiple lessons)
One of the most important things I like about Node.js and MongoDB (Mongoose in my case) is that you are writing the query commands sometimes exactly like you write them in the MongoDB shell.
P.S. Last but not least, checkout the videos from 10gen related to Node.js and MongoDB, there are lots of them (and people using Node with Mongo in production): http://www.10gen.com/presentations#programming_lang__javascript_nodejs

Is there a Recommended node.js equivalent for the Kohana Framework

The more I look at node.js the more, I'm really beginning to like it. Everything is an object like ruby, but it isn't as different ( hippie like :P ). Also you don't have to relearn all these syntaxes that are all globals array_map, array_push...
So is there a similar equivalent of Kohana php for node.js?
I'm assuming node.js is ready for prime time if I wanted to set up a server and everything, or is there anything that I shoud be concerned/worried about. I noticed nodejs.com demo is down, which is a bit concerning if I wanted to go live.
I think express.js is the most common framework for node.js as of now.
If you want to get started with node.js which is freakin awesome if you ask me, you should look(comprehend) into:
npm
http://search.npmjs.org/
express
socket.io
redis
node_redis
mongodb
mongoose
everyauth
Like Jorge said express.js is a very popular framework to develop websites. Also if you master these topics I am sure you will really love node.js.
I am developing a framework inspired by Kohana at https://github.com/sadjow/falcon

Is Node.js a good alternative to build complete websites?

I'm wondering if using Node.js (express.js) is the best option to go for a complete website. I've been using Rails + Node.js and am wondering if this is still the best option or if I should move completely to Node.js.
Are there websites built completely with node.js? I imagine it must lack many things Rails offers.
I imagine it must lack many things
Rails offers.
I gave a short list below but I would like to know what you could be missing and I think(almost certain) we can give you some alternatives on node.js.
Modules
node.js is getting pretty complete and I think you can run your entire site using only node.js using for example the following modules. I assume you know about npm. If not I really advice you to google for it and learn that. To search npm you can use http://search.npmjs.org:
web framework:
High performance, high class web
development for Node.js
https://github.com/visionmedia/express
Socket.IO aims to make realtime apps possible in every browser and mobile
device, blurring the differences
between the different transport
mechanisms.
https://github.com/learnboost/socket.io-node
I believe with these two web-frameworks you can create a lot of sites. For example express is a very powerfull web framework and supports a lot of cool things like:
session support.
a lot powerful template engines. I like Jade for example. You could also share these between client and server a lot of the times easily.
excellent routing.
just to name a few.
database:
Redis is an open source, advanced
key-value store. It is often referred
to as a data structure server since
keys can contain strings, hashes,
lists, sets and sorted sets.
https://github.com/mranney/node_redis
MongoDB (from "humongous") is a scalable, high-performance, open source,
document-oriented database.
Mongoose is a MongoDB object modeling tool designed to work in an
asychronous environment.
https://github.com/learnboost/mongoose/
With those two databases I think you should be able to accomplish most of your tasks. The nice thing is that Redis is extremely fast/simple advanced KV-store(dataset in memory/also supports VM) and supports replication while Mongodb is more completely(slower then redis) and also supports sharding.
authentication:
Authentication and authorization (password, facebook, & more) for your node.js Connect and Express apps.
https://github.com/bnoguchi/everyauth
Like I said previously you can get a long way with only these modules.
Express.js is more akin to Sinatra. They're simpler frameworks than rails.
Express's list of sites is fairly small http://expressjs.com/applications.html
So I think it's also good to look at Sinatra's list http://www.sinatrarb.com/wild.html
So to answer your questions in reverse order. Yes it lacks all the features of rails. Yes there are sites written completely in Express. And going to 100% Node.js might be the right decision for your site.
It depends on which features you'd miss and what performance you need.
I'm not sure, but I guess it's perfectly possible. I have built complete sites using plain server side javascript for years without problems. The advantage of node.js seems to be its event driven model and things like socket.io. I just started experimenting with it, I'll probably will try porting an existing site to node.js.
Here you can find a large list of sites built with node.js.
Finally, you may want to read: What it’s like building a real website in Node.js
Yes, as of now node.js lacks many (well, at least a few) things rails offers. Eventually the set of available node.js modules will collectively provide good alternatives to RoR across the board. Or at least different (and often more modern) approaches to the same fundamental problems. There are still some important things missing in the node.js ecosystem including a good ORM for postgresql (rails has ActiveRecord which is great) and a good DB schema management subsystem. Both of these do not exist in the node.js ecosystem as of this moment, but surely they will be there in due time. Rails has these down pat right now.
There are some tricks node.js has that RoR doesn't. Debugging in node.js is more seamless than RoR and express.js is more flexible. Express is the library approach (you tell it what to do) whereas rails is the framework approach (you fill out the boilerplate it creates for you). There are also some fantastic things like stylus and jade, which have equivalents in rails, but when you have a full app written in one language (either javascript or CoffeeScript, which I prefer) and everything is in a modern node.js/TJ Holowaychuck style, you get a level of cohesiveness that is really nice to work within.
The other thing to keep in mind is that while the list of available node.js modules is quite impressive, many of them are not as mature and battle-tested as their rails/django analogs. It's hit or miss, so beware.

Categories