使用node.js进行丰富的应用程序开发

我是node.js的新手,已经提出了使用Node.js开发基于Web的丰富应用程序的要求。

现在我正在研究node.js的入门指南。 我有机会看到这里的页面,并与数百个框架混淆。 我不知道select一个合适的框架,需要帮助做出完美的决定。 让我解释我的要求。

  1. 要为所有function开发RESTfull API。 (OAuth上的任何图书馆?)
  2. 想要在API之上开发一个Web应用程序。 应用程序的devise必须要在客户端开发主要的function。 意思是,所有的业务逻辑都必须在客户端开发。 我听说一些像Backbone.js,Underscore.js这样的图书馆已经在做这个工作,但是没有清楚的想法。

请build议我的框架,这将更好地满足我的要求。

谢谢,

这是我用于我的应用程序的一个很好的技术堆栈:

服务器端:

  • Express.js
  • 把手
  • Passport.js
  • mongoose
  • MongoDB的
  • Caolanforms(但是我目前正在执行我自己的表单处理程序)
  • CoffeeScript的

客户端:

  • 把手
  • jQuery的
  • Require.js
  • Backbone.js的
  • text.js(require.js的插件)
  • Coffeescript(plugin for require.js。我的.coffee是使用r.js在开发和服务器端编译的客户端)

如果你愿意的话,我可能会稍后再做一个示例程序。

[编辑]

确定这里是一个示例应用程序。

项目结构:

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 

服务器端:

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.compile template render: => html = @template {models: @collection.models} @$el.html(html) return @ 

sampleTemplate.hbs

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

好吧,这是必不可less的。 现在,您将不得不学习如何使用Backbone.Collection , Backbone.Model ,如何configurationRequire.js ,如何configurationPassport.js以及如何制作Mongoose模型 。 你可以使用Less中间件来编译你的style.less

不要忘记,您可以使用r.js预编译所有客户端应用程序。

现在我希望这个网页不会被遗忘,并且会帮助任何未来碰到的人。

这是一篇很好的文章,可以帮助解释最stream行的JavaScript框架:

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

最终,最好的办法是制作一个你认为可以帮助你的框架的简短列表,然后把每个人的手弄脏一点,看看哪个最适合你的应用程序和编程风格。