Questions about node.js - javascript

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

Related

MongoDB run locally or through Atlas?

Is it better to learn MongoDB through MongoDB Atlas or to have MongoDB downloaded locally?
When I go to https://docs.mongodb.com/manual/tutorial/getting-started/ I see there are two options for downloading MongoDB. I'm guessing it doesn't matter which one you download but if there is a better option, it would be nice to know.
When you're getting started, i suggest the quickest option. Knowing how to configure/install a local instance of Mongo is certainly important, but it can sometimes be a drag and prevent you from the more 'enjoyable' parts of learning a new technology.
I personally recommend going with Atlas at first. After you've seen enough mongo to get familiar with the shell commands, take a swing at installing it locally.

Using a database for a Node.js application that runs in the terminal

I'm currently writing a program that is a To-Do list that just runs locally on my machine in the terminal screen(written in node.js, no extra dependencies). I've set up everything and it works totally fine, but I have never actually used any databases other than just session cookies on the browser. What would you all suggest I use when all I want to do is learn how to store some simple data in a database and then be able to manipulate it in the same fashion.
Any help would be greatly appreciated on this one! I'm really just looking for suggestions on a good database, as well as a bit of guidance on the best way to use that particular technology. I'm familiar with SQL and NoSQL databases, but like I said, I have never even used one on an actual application.
Thanks in advance.
In my view, You can use mongodb which is easy to configure and manipulate data. It helps you to work on json objects directly from database. Use express to create your RESTful endpoints and exposed data. Sometime back i use it for angular application, repo link is below for your reference :
AngularJs, ExpressJs, MongoDB application
Hope this helps.
Cheers
You can use sqlite which provides a good SQL API but keeps things very simple by simply using a file on your disk and accessing it through code directly in your application. You don't need to start another server and take care of configuring it.
For a simple To-Do list that should be more than adequate for storing your data whilst keeping your configuration simple and easy.
Here's a tutorial on how to set it up:
http://www.sqlitetutorial.net/sqlite-nodejs/
You'll essentially be using the sqlite3 npm package: https://www.npmjs.com/package/sqlite3
That page also comes with brief usage instructions.
Nodejs has client libraries for database interaction
Ex.
For SQL database:
postgresql : https://github.com/brianc/node-postgres
For NoSQL db:
mongodb : https://github.com/Automattic/mongoose
You can also create pool of db connections

Need an Expressjs-nodejs-mongoose tutorial to build a simple RESTful service

Being fairly new to nodejs and mongoDB,
I have looked up all over the net to get a tutorial where express is used with node and mongoose.
What I need is express's route feature to detect requests and perform database operations accordingly.
I do not need jade or any other templates , I just plan to return a json structure read from monogDB/mongoose on an express route request.
A simple server.js file would suffice where a single express route is provided with interaction using mongoose to a mongodb database.
I suppose this is quiet simple while speaking but its really difficult to put these pieces together when one doesnt know much about node / mongo / mongoose. and the examples available on the net are overkill.
Please help !
I think you should behave more responsibly by first searching and putting your efforts.
This is a very detailed tutorial about the same requirements,
http://scotch.io/tutorials/javascript/build-a-restful-api-using-node-and-express-4
But please be more responsible to the community in future.

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

Framework + database for node.js

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/

Categories