Express.Js, Node.Js, MongoDB Questions

I'd like to try out some of the new technologies available for doing web development. I've been using php frameworks, rails and asp.net mvc for quite some time now and I saw that Node.Js provided a lot of good stuff to the table.

But I don't know how and where to begin. I setup mongodb, node.js and express.js and I played with it a bit but I'd like to know how to make the link between express.js and mongodb (I have mongoose but I don't know how to include it yet) and I'd like some brief and simple examples (unlike stuff that is in express.js docs) to see some actual usage cases.

I'd like to build some quick content management system and with a simple frontend, and I wanted to make a change and try that out. Any advice and help will be appreciated!

[edit: I already read http://howtonode.org/express-mongodb it helped but it doesn't explain much about how to do it]

Thanks!

-------------Problems Reply------------

Here's a get started blog post for Node.js + MongoDB. You can easily ignore the Cloudfoundry stuff. Mongoose is a layer over the basic driver, so you should probably start with the basic driver.

If you want some code / ideas to steal, take a look at railwayjs.

Start simple. Code a basic web site using vanilla node.js standard library HTTP module (require('http');). Learn the basics of the http request and response interfaces, especially the evented interfaces for streaming data. Learn the basic fs module and how to take plain .html files on disk and send them as HTTP responses. You can do this in a single .js file without needing any third party npm modules. Full stop until you have that done and it makes sense to you. If something isn't clear, experiment until it is (and ask more questions here). This is straightforward, but there are still lots of ways to get confused.

Once you have that, you'll see that it's actually already pretty high-level and straightforward to write a small web site. Next add express.js. Study the concept of connect middleware and how the middleware chain works, including the next callback, bodyParser, and static middlewares. Make sure you understand why middleware often needs to be applied in a specific order and how it breaks if you apply them in the wrong order. Understand express's app.error, dynamicHelpers, and most of the examples in the documentation, which are all very good and realistic but I agree because they are just tiny snippets they leave a lot of room for questions about the surrounding context and how things fit together entirely. Don't go nuts with complex layouts and templating stuff, just stick to the basics.

Then maybe start persisting some domain level data into simple files on the filesystem, perhaps just .json data. This will present new challenges and help you understand more complex things in an async world. In particular, if you start having to do a series of operations like recursively ensure a directory path exists and then write a new file in the final leaf directory, you will want to look at a flow control library like async or async.js or similar.

Only then should you start adding mongoose and mongodb to your stack and replace your fs.writeFile calls with mongoose model.save calls.

For me the biggest help I found when experimenting with all these awesome new technologies was looking at this sample application:

Demo App - https://github.com/madhums/nodejs-express-mongoose-demo

It shows some good usage of how to organise a node-express application, some common utilities for showing mongoose validation errors messages, stylus for css, jade views, etc. And the author appears to take requests if you think something should be added to the demo app to help others learn a new express/mongo/etc feature - I haven't asked personally but there is a check-list on the github page showing what features are completed and what's upcoming.

I would also recommend just getting your hands dirty :) Come up with a simple idea and try to build it. And when something doesn't feel right or you have a block then there's a pretty amazing and growing community out there.

Here are some tutorials not mentioned above:

Mongoskin (mongoose alternative) - http://www.hacksparrow.com/mongoskin-tutorial-with-examples.html
Exress JS tutorial: http://www.hacksparrow.com/express-js-tutorial.html

Also if you go to the github page for expressjs you will see many examples of specific express functionality - which goes into some great specifics:

Express js examples: https://github.com/visionmedia/express/tree/master/examples

Category:javascript Views:0 Time:2012-02-18

Related post

  • Learning Express for Node.js 2011-11-15

    Anyone have pointers to good resources for learning Express? I'm aware of the documentation and the nodetuts.com videos. Curious if there are any other good resources out there. --------------Solutions------------- If I would do it all over again wit

  • Express.js, Node.js Jade - Following the expressjs.com tutorials, and getting errors 2011-05-01

    Well I'm trying to get into Node.js / Express.js - however I've been having a few issue going through the screencast, the first issue, now resolved, was pretty obvious when it was spotted (Express.js, Node.js Jade vim). However, I'm now getting the f

  • Is there anyway Express in Node.js can have more than one static folder? 2011-08-09

    I'm working on a project where there is a user uploaded collection of styles, scripts and images and then their is my app's collection of styles, scripts and images. They're two different places on my server. Is there anyway I can setup Express in No

  • Node.js + MongoDB this._handle.write(data) bugging in net.js 2011-12-16

    I'm working with Node.js + MongoDB for an application. From time to time, just before some AJAX request to the server, I get this error: net.js:434 var writeReq = this._handle.write(data); ^ TypeError: Cannot call method 'write' of null at Socket._wr

  • AngularJS, plotting markers on a LeafletJS map via Express, Node and MongoDB. How do you do it? 2012-11-26

    I have begun writing an app with AngularJS, LeafletJS, NodeJS, Express and MongoDB (MongoJS). The app features a navigation of categories and a large map. The categories list things like restaurants, parks, shops and businesses. Clicking on each one

  • Advice on creating a multi-tenant SAAS App with MEAN Stack (Mongodb, express, angular, node) 2014-05-26

    I am trying to wrap my head around developing an SAAS application with MEAN stack rather than PHP and MySQL. I need advice on a good way to create a multi-tenant application with mongodb. I know from previous reading that I don't want to do one datab

  • Express on Node - what data store? 2011-11-10

    I'm doing my first project in node/express. I'm looking to implement a data store and noticed that express is using redis as a session store. Does this mean that express installs redis by default? The reason I ask is that I pondering whether to insta

  • hot plug a node w/ MongoDB 2010-10-01

    We are evaluating MongoDB with my team and I have a couple questions that I'm sure are answered somewhere on the web but I couldn't find the answers... 1) Can we hot plug a data node in the MongoDB cluster? If we can how difficult is it? 2) It seems

  • Node.js / mongoDB, cannot retreive records 2011-04-10

    In my node.js / express app, when I look into mongoDB, I got the following: > db.things.find()[0]._id ObjectId("4da06702584ca3f402000001") It does exists a collection with id 4da06702584ca3f402000001. But When I use a request, I cannot get it back

  • Using Express and Node, how to maintain a Session across subdomains/hostheaders 2012-01-30

    I have a single node server that responds to requests and redirects a user based on host headers. The usage is that the static/home site lives at www and each user has their own sub domain (i.e. www.example.com and site.example.com). The routing is a

  • Node.js & MongoDB memory consumption 2012-02-05

    I received an email yesterday from my hosting provider that my Node.js (Express) app and MongoDB (both running with Forever) are consuming too much memory - about 300MB (my hosting limit is 256MB). That node app was just a simple demo generated by ex

  • Breeze with Node and Mongodb - getting a working Zza sample on Debian? 2014-04-16

    I can't get a version of the Breeze Zza sample application to work (with Node, Express, Mongodb). I've tried running the provided sample, as well as digging out a later version from github but so far no joy. The Zza version provided from the page htt

  • xpath: how to express text nodes? 2009-10-17

    consider: text 1 text 2 text 3 how can you express the textnode in xpath ? --------------Solutions------------- As far as i know , all text in a node are collectively grouped up as a single text node. They are not hierarchical so there wont be more t

  • How to I load a javascript file using express and node.js? 2010-10-22

    I'm trying to figure out how to load a simple javascript client-side library while using node.js and express. Any ideas? See below. HAML: %script{type: 'text/javascript', src: '/jquery-1.4.3.js'} %script{type: 'text/javascript', src: '/client.js'} ap

  • Express.js, Node.js Jade vim 2011-04-30

    Help, before I throw my beautiful, expensive MacBook Pro to the ground in a fit of annoyance. I'm trying to get something working in Expressjs, and it's really getting on my nerves. I'm following the tutorial on: expressjs.com/screencasts.html Screen

  • Callbacks with node.js/MongoDB/Mongoose 2011-06-24

    I'm trying to learn the Mongoose ORM for MongoDB and node.js. I want to query documents in my database, perform an action on each one, and then perform another action after all of the previous actions are complete. In other words, I want to do someth

  • Node.js mongodb-native driver authentication in cloudfoundry 2011-08-04

    I'm currently trying to mess around with Node and Mongo for a bit of self learning. Ive been looking at various blog entries and have been messing with getting a simple blog written in node with a mongo db working. Anyway I'm having trouble making it

  • How to use SCSS with Express ? (Node.js) 2011-10-08

    Is there any way to use SCSS with Express ? I tried with : app.use(express.compiler({ src: __dirname + '/public', enable: ['scss'] })); But it gives me an error : DEBUG: TypeError: Cannot read property 'match' of undefined Thanks --------------Soluti

  • Node.JS MongoDB Order of Operations Use Case 2011-10-20

    What is the order of operations for the mongodb-native driver? Let's say you have a class that's purpose is to save a document of some sort and let's say it has a long life. How many times should open be called? Once per db write? When is close suppo

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.174 (s). 11 q(s)