最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Rich app development with node.js - Stack Overflow

programmeradmin4浏览0评论

I'm new to node.js, have given a requirement to develop a rich web based application using Node.js.

Right now I'm working on the getting started guides on node.js. I had a chance to look the page here and got confused with hundreds of frameworks. I have no idea to choose a suitable framework, and need help on this to make a perfect decision. Let me explain my requirement.

  1. Want to develop RESTfull API for all the functionalities. (Any libraries on OAuth?)
  2. Want to develop a web application on top of the API. The application has to be designed in such a way that major functionalities should be developed in the client side. Means, all the business logic has to be developed in the Client side. I heard some libraries like Backbone.js, Underscore.js already doing the job, but didn't have clear idea on it.

Please suggest me the frameworks which will do better for my requirement.

Thanks,

I'm new to node.js, have given a requirement to develop a rich web based application using Node.js.

Right now I'm working on the getting started guides on node.js. I had a chance to look the page here and got confused with hundreds of frameworks. I have no idea to choose a suitable framework, and need help on this to make a perfect decision. Let me explain my requirement.

  1. Want to develop RESTfull API for all the functionalities. (Any libraries on OAuth?)
  2. Want to develop a web application on top of the API. The application has to be designed in such a way that major functionalities should be developed in the client side. Means, all the business logic has to be developed in the Client side. I heard some libraries like Backbone.js, Underscore.js already doing the job, but didn't have clear idea on it.

Please suggest me the frameworks which will do better for my requirement.

Thanks,

Share Improve this question asked Feb 19, 2013 at 13:17 started on node.jsstarted on node.js 6071 gold badge8 silver badges14 bronze badges 4
  • There is not a hundred of MVC frameworks , 3/4 server side at best and the same amount client-side. – mpm Commented Feb 19, 2013 at 13:21
  • @mpm: I think you're underestimating. TodoMVC lists more than 25 client-side frameworks, and more than pile to client-side JS, as well as a number of other categories. – Scott Sauyet Commented Feb 19, 2013 at 13:59
  • @Scott Sauyet how many of these framework have extended documentation , blog posts ,support and tutorials over the internet ? that's how you tell wether a framework is worth using or not. 80% of these frameworks are insignificants from an adoption perspective. – mpm Commented Feb 19, 2013 at 14:13
  • @mpm: Which ones are insignificant? I've heard of all but three, and tried about half of them. And how widely adopted does a framework have to be before you're willing to consider it? – Scott Sauyet Commented Feb 19, 2013 at 14:17
Add a ment  | 

2 Answers 2

Reset to default 16

Here is a good tech stack that I use for my applications:

Server side:

  • Express.js
  • Handlebars
  • Passport.js
  • Mongoose
  • MongoDB
  • Caolan forms (But I am currently in the process of implementing my own form handler)
  • Coffeescript

Client side:

  • Handlebars
  • Jquery
  • Require.js
  • Backbone.js
  • text.js (plugin for require.js)
  • Coffeescript (plugin for require.js. My .coffee are piled client side in dev and server side in prod using r.js)

I might make a little sample app later if you want.

[EDIT]

ok here is a sample app.

Project structure:

forms
  |___ sampleForm.coffee
models
  |___ sampleModel.coffee
public
  |___ images
  |___ stylesheets
  | |___ style.less
  |___ sampleapp
    |___ main.js
    |___ cs.js
    |___ text.js
    |___ require.js
    |___ collections
    | |___ sampleCollection.coffee
    |___ models
    | |___ sampleModel.coffee
    |___ templates
    | |___ sampleTemplate.hbs
    |___ lib
    | |___ handlesbars.js
    | |___ backbone.js
    | 
    | |___ ...
    |___ views
      |___ sampleView.coffee
routes
  |___ index.coffee
views
  |___ index.hbs
app.js
application.coffee
package.json

Server side:

app.js

require('coffee-script');
module.exports = require('./application.coffee');

application.coffee

... standard express.js initialization
require("./routes")(app)
... start server

index.coffee

SampleModel = require "../models/sampleModel"
module.exports = (app) =>
  app.get "/index", (req,res) =>
    return res.render "index"

  app.get "/samplemodels", (req,res) =>
    SampleModel.find {}, (err, models) =>
      return res.send 404 if err or !models
      return res.send models
    return

index.hbs

<!DOCTYPE HTML>
<html>
<head>
  <title>Sample app</title>
  <link type="text/css" href="/stylesheets/style.css" rel="stylesheet" >
  <script src="/mainapp/require.js" data-main="/mainapp/main"></script>
</head>
<body>
  <div id="main-content"></div>
</body>
</html>

main.js

require.config({...}) // Configure requires.js...

require(["jquery", "cs!models/samplemodel", "cs!views/sampleview","cs!collections/samplecollection"], function ($, Model, View, Collection) {
  var collection = new Collection();
  collection.fetch();
  var view = new View({collection: collection});
  $("body").html(view.render().$el);
})

sampleview.coffee

define ["backbone", "jquery", "handlebars","text!templates/sampleTemplate.hbs"], (Backbone, $, Hbs, template) =>
  class MainView extends Backbone.View
    initialize: =>
      @collection.on "change", @render
      @template = Hbs.pile template
    render: =>
      html = @template {models: @collection.models}
      @$el.html(html)
      return @

sampleTemplate.hbs

{{#models}}
  <p>{{name}}</p>
{{/models}}

Ok so that is the essential. Now you'll have to learn how to use Backbone.Collection, Backbone.Model, how to configure Require.js, how to configure Passport.js and how to make a Mongoose model. You can use the Less middleware to pile your style.less

Don't forget that you can prepile all your client application with r.js.

Now I hope that this page will not be forgotten and that it will help anyone who e across it in the future.

This is a great article which helps explain the most popular javascript frameworks:

http://coding.smashingmagazine./2012/07/27/journey-through-the-javascript-mvc-jungle/

Ultimately, the best way is to make a short-list of frameworks you think will help you, then just get your hands dirty with each one for a bit and see which most suits your app and programming style.

发布评论

评论列表(0)

  1. 暂无评论