5

私は node.js を初めて使用し、Node.js を使用してリッチな Web ベースのアプリケーションを開発する必要がありました。

現在、node.js の入門ガイドに取り組んでいます。ここのページを見る機会があり、何百ものフレームワークと混同しました。適切なフレームワークを選択する方法がわかりません。完璧な決定を下すには、これについて助けが必要です。私の要件を説明しましょう。

  1. すべての機能の RESTfull API を開発したい。(OAuth のライブラリはありますか?)
  2. API 上で Web アプリケーションを開発したい。アプリケーションは、主要な機能がクライアント側で開発されるように設計する必要があります。つまり、すべてのビジネス ロジックをクライアント側で開発する必要があります。Backbone.js や Underscore.js などのいくつかのライブラリが既に機能していると聞きましたが、明確なアイデアはありませんでした。

私の要件により適したフレームワークを提案してください。

ありがとう、

4

2 に答える 2

16

これは、私がアプリケーションに使用する優れた技術スタックです。

サーバ側:

  • Express.js
  • ハンドルバー
  • Passport.js
  • マングース
  • モンゴDB
  • Caolanフォーム(ただし、現在、独自のフォームハンドラーを実装中です)
  • コーヒースクリプト

クライアント側:

  • ハンドルバー
  • Jクエリ
  • Require.js
  • Backbone.js
  • text.js (require.js のプラグイン)
  • Coffeescript (require.js のプラグイン。私の .coffee は、r.js を使用して、dev ではクライアント側でコンパイルされ、prod ではサーバー側でコンパイルされます)

必要に応じて、後で小さなサンプル アプリを作成するかもしれません。

[編集]

これがサンプルアプリです。

プロジェクトの構造:

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');

アプリケーション.コーヒー

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

インデックスコーヒー

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);
})

サンプルビュー.コーヒー

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 モデルの作成方法を学習する必要があります。Less ミドルウェアを使用して、style.less をコンパイルできます。

すべてのクライアント アプリケーションをr.jsでプリコンパイルできることを忘れないでください。

このページが忘れられず、将来このページに出くわした人の助けになることを願っています。

于 2013-02-19T13:34:02.047 に答える
2

これは、最も一般的な JavaScript フレームワークを説明するのに役立つ素晴らしい記事です。

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

最終的には、役立つと思われるフレームワークの短いリストを作成し、それぞれのフレームワークを少し試して、自分のアプリとプログラミング スタイルに最も適したフレームワークを確認するのが最善の方法です。

于 2013-02-19T13:20:27.493 に答える