読了: 約 5 分
最近Angular.js対Backbone.jsという話が多い気がするのは私だけではないでしょうが、Mean Stackというスピード開発したい時に使うステキなフロントエンドの開発環境があるという事を聞いてググってメモ。
MEAN Stackとは
下記の頭文字。
僕もAngularを触った事がないのでお試し気分でウキウキウォッチング。
M: MongoDB
E: Express
A: AngularJS
N: Node
通常通りtemplateはdefaultはjadeに設定されている模様。

package.json
"dependencies": {
"express": "latest",
"jade": "latest",
"mongoose": "latest",
"connect-mongo": "latest",
"connect-flash": "latest",
}
ディレクトリ構造はこんな感じ。indexのtemplateはpublicのhtmlを使っているみたいですが、
大枠はjadeに書かれています。

signin、signupが既に用意されていて、見てみるとこんな感じ。ステキです。

routingの設定はconfigにまとめられていて、非常にわかりやすい。
//public/js/config.js
angular.module('mean').config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/articles', {
templateUrl: 'views/articles/list.html'
}).
when('/articles/create', {
templateUrl: 'views/articles/create.html'
}).
when('/articles/:articleId/edit', {
templateUrl: 'views/articles/edit.html'
}).
when('/articles/:articleId', {
templateUrl: 'views/articles/view.html'
}).
when('/', {
templateUrl: 'views/index.html'
}).
otherwise({
redirectTo: '/'
});
}
]);
ただ、expressか何かバージョンの問題でpbkdf2Syncメソッドが使えない問題が起きてしまうので試したい場合は
github でmergeされたものを元に戻すと上手くユーザーが登録されて投稿出来るようになります。
TypeError: Object #<Object> has no method 'pbkdf2Sync'
at model.UserSchema.methods.encryptPassword (/<pj環境>/mean-t/mean/app/models/user.js:120:23)
//もとに戻す
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
こんな感じで投稿のテストも出来ます。

mongodbの起動
こういう時にWEB開発の土台力の必要性を感じるのですが、まぁ悔やんでも居られないので慣れろという事で
当たり前ですが、mongodb起動しないとエラーになります。
mongo – couldn’t connect to server 127.0.0.1:27017
This is a pervasive problem with mongo and am rather clueless. Restarting does not help.I a…
Error: failed to connect to [localhost:27017]
at Server.connect.connectionPool.on.server._serverState (/<pj環境>/mean-t/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
at EventEmitter.emit (events.js:126:20)
at connection.on._self._poolState (/<pj環境>/mean-t/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
at EventEmitter.emit (events.js:99:17)
at Socket.errorHandler (/<pj環境>/mean-t/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
at Socket.EventEmitter.emit (events.js:96:17)
at Socket._destroy.self.errorEmitted (net.js:329:14)
at process.startup.processNextTick.process._tickCallback (node.js:244:9
まとめ
大枠用意されているので小さいアプリなら爆速で創れそうな気がしますね
Gruntでlivereload用意されてて考えられているので便利ですね。