2013-02-19 47 views
5

我是node.js的新手,需要使用Node.js開發基於Web的豐富應用程序。使用node.js進行豐富的應用程序開發

現在我正在開始關於node.js的入門指南。 我有機會看到頁面here,並與數百個框架混淆。我不知道要選擇一個合適的框架,並且需要幫助才能做出完美的決定。讓我解釋我的要求。

  1. 想要爲所有功能開發RESTfull API。 (OAuth上的任何庫?)
  2. 想要在API之上開發Web應用程序。 應用程序的設計必須在客戶端開發主要功能。意思是,所有的業務邏輯都必須在客戶端開發。我聽說一些像Backbone.js,Underscore.js這樣的圖書館已經在做這項工作,但沒有清楚的想法。

請建議我的框架,這將更好地滿足我的要求。

感謝,

+0

沒有MVC框架的一百年,3/4服務器端最好和相同數量的客戶端。 – mpm 2013-02-19 13:21:48

+0

@mpm:我認爲你低估了。 [TodoMVC](http://todomvc.com/)列出了超過25個客戶端框架,並且多於編譯到客戶端JS以及其他一些類別。 – 2013-02-19 13:59:02

+0

@Scott Sauyet這些框架中有多少可以通過互聯網擴展文檔,博客文章,支持和教程?這就是你如何告訴框架值得使用還是不適用。從採用的角度來看,這些框架中的80%是微不足道的。 – mpm 2013-02-19 14:13:21

回答

15

這裏是我用我的應用良好的技術堆棧:

服務器端:

  • Express.js
  • 把手
  • Passport.js
  • 貓鼬
  • MongoDB
  • Caolan表格(但我現在是我ñ實現我自己的表單處理程序)
  • CoffeeScript的

客戶端的過程:

  • 把手
  • jQuery的
  • Require.js
  • Backbone.js的
  • 文本.js(用於require.js的插件)
  • Coffeescript(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}} 

好了,所以這是必要的。現在您將不得不學習如何使用Backbone.Collection,Backbone.Model,如何配置Require.js,如何配置Passport.js以及如何製作Mongoose model。你可以使用Less middleware來編譯你的style.less

不要忘了你可以使用r.js預編譯所有的客戶端應用程序。

現在我希望這個網頁不會被遺忘,並且它會幫助任何未來遇到它的人。

+0

謝謝,你能否讓我做一個小樣本應用程序 – 2013-02-19 14:11:16

+0

我會在這個列表中替換成Jade的把手,但其餘的都很好。 – gustavohenke 2013-02-19 14:17:35

+0

Jade更靈活,但在我看來,遠離真正的html。另外,我認爲Jade會導致一些開發人員在視圖層中寫入很多邏輯。 – 2013-02-19 14:20:32

相關問題