{"id":686,"date":"2012-07-21T23:05:28","date_gmt":"2012-07-22T06:05:28","guid":{"rendered":"http:\/\/h2plus.biz\/hiromitsu\/?p=686"},"modified":"2018-08-06T14:08:00","modified_gmt":"2018-08-06T21:08:00","slug":"jtpa%e3%82%ae%e3%83%bc%e3%82%af%e3%82%b5%e3%83%ad%e3%83%b3%e3%81%a7%e3%81%aenode-js%e3%83%8f%e3%83%83%e3%82%ab%e3%82%bd%e3%83%b3","status":"publish","type":"post","link":"https:\/\/h2plus.biz\/hiromitsu\/entry\/686","title":{"rendered":"JTPA\u30ae\u30fc\u30af\u30b5\u30ed\u30f3\u3067\u306enode.js\u30cf\u30c3\u30ab\u30bd\u30f3"},"content":{"rendered":"<p>7\u670820\u65e5\u306b\u50ac\u3055\u308c\u305fJTPA\u30ae\u30fc\u30af\u30b5\u30ed\u30f3\u300c\u9752\u6728\u6df3\u6c0f\u3068Node.js\/Heroku\u3092\u4f53\u9a13\u3059\u308b\u300d\u306b\u30dc\u30e9\u30f3\u30c6\u30a3\u30a2\u306e\u30c6\u30af\u30cb\u30ab\u30eb\u30b5\u30dd\u30fc\u30c8\u30b9\u30bf\u30c3\u30d5\u3068\u3057\u3066\u53c2\u52a0\u3057\u3066\u304d\u305f\u3002JTPA\u3067\u306e\u30cf\u30c3\u30ab\u30bd\u30f3\u306f\u3001<a href=\"http:\/\/h2plus.biz\/hiromitsu\/entry\/267\">Hadoop\u3067\u59cb\u3081\u308b\u4e26\u5217\u30c7\u30fc\u30bf\u89e3\u6790<\/a>\u4ee5\u6765\u3002\u53c2\u52a0\u8005\u306f\u5404\u3005\u30e9\u30c3\u30d7\u30c8\u30c3\u30d7\u3092\u6301\u3061\u8fbc\u307f\uff08\u53c2\u52a0\u8005\u306e9\u5272\u304cMac\u3068\u3044\u3046\u306e\u304c\u30b7\u30ea\u30b3\u30f3\u30d0\u30ec\u30fc\u3089\u3057\u3044\uff09\u3001\u30ac\u30a4\u30c9\u306b\u5f93\u3044\u306a\u304c\u3089\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u3044\u304f\u308f\u3051\u3060\u304c\u3001Hadoop\u306e\u6642\u3068\u540c\u69d8\u306b\u53c2\u52a0\u8005\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30ad\u30eb\u306f\u30d0\u30e9\u30d0\u30e9\u3002\u81ea\u5206\u3067Web\u30b5\u30fc\u30d3\u30b9\u3092\u4f5c\u3063\u305f\u3053\u3068\u304c\u3042\u308b\u4eba\u3082\u3044\u308c\u3070\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u305f\u3053\u3068\u304c\u306a\u3044\u3068\u3044\u3046\u521d\u5fc3\u8005\u3082\u3044\u305f\u3051\u308c\u3069\u3001\u30db\u30b9\u30c8\u5f79\u306e\u9752\u6728\u6c0f\u306e\u7d20\u6674\u3089\u3057\u3044\u30d5\u30a1\u30b7\u30ea\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u3001\u6642\u9593\u5185\u306b\u5168\u54e1\u304c\u300cheroku\u4e0a\u3067MySQL\u3092\u4f7f\u3063\u305fnode\u30a2\u30d7\u30ea\u3092\u52d5\u304b\u3059\u300d\u3068\u3044\u3046\u30b4\u30fc\u30eb\u306b\u8fbf\u308a\u7740\u304f\u3053\u3068\u304c\u3067\u304d\u305f\u3002<\/p>\n<p><!--more--><br \/>\n\u3069\u3093\u306a\u3053\u3068\u3092\u3084\u3063\u305f\u306e\u304b\u3092<a href=\"https:\/\/github.com\/bow-fujita\/jtpa-july-2012\">github\u4e0a\u306b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3068\u5171\u306b\u307e\u3068\u3081\u3066\u304a\u3044\u305f<\/a>\u306e\u3067\u3001\u30cf\u30c3\u30ab\u30bd\u30f3\u306e\u53c2\u52a0\u8005\u3067\u5fa9\u7fd2\u3057\u3066\u304a\u304d\u305f\u3044\u4eba\u3001\u6b8b\u5ff5\u306a\u304c\u3089\u4f1a\u5834\u306b\u8db3\u3092\u904b\u3079\u306a\u304b\u3063\u305f\u4eba\u306f\u53c2\u8003\u307e\u3067\u3002\u5f53\u65e5\u306f\u6642\u9593\u306e\u95a2\u4fc2\u4e0a\u3001<code>app.js<\/code>\u306b\u3059\u3079\u3066\u306e\u30b3\u30fc\u30c9\u3092\u8a70\u3081\u8fbc\u3093\u3067\u3044\u304f\u30b9\u30bf\u30a4\u30eb\u3060\u3063\u305f\u3051\u3069\u3001github\u306b\u8f09\u305b\u305f\u30b3\u30fc\u30c9\u306f\u82e5\u5e72\u306a\u304c\u3089<code>routes\/index.js<\/code>\u306b\u30b3\u30fc\u30c9\u3092\u5206\u6563\u3055\u305b\u3066\u3044\u308b\u3002\u307e\u3041\u5165\u9580\u306a\u306e\u3067\u3053\u3093\u306a\u3082\u3093\u3067\u3059\u306a\u3002<\/p>\n<p>heroku\u4e0a\u3067\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u306f<a href=\"https:\/\/elements.heroku.com\/addons\/cleardb\" class=\"broken_link\">ClearDB MySQL Database<\/a>\u3092\u4f7f\u3063\u3066\u305f\u306e\u3067\u3001<code>heroku config<\/code>\u3067\u8868\u793a\u3055\u308c\u308b\u74b0\u5883\u5909\u6570<code>CLEARDB_DATABASE_URL<\/code>\u304b\u3089\u624b\u52d5\u3067<code>mysql<\/code>\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u8a2d\u5b9a\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u30b7\u30fc\u30f3\u304c\u3042\u3063\u305f\u304c\u3001\u3053\u3046\u3044\u3046\u306e\u306f\u95a2\u6570\u3092\u4f5c\u3063\u3066\u304a\u304f\u3068\u4f7f\u3044\u56de\u3057\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction parseClearDbUrl() {\r\n  if(!process.env.CLEARDB_DATABASE_URL) {\r\n    return null;\r\n  }\r\n\r\n  var url = require('url')\r\n    , dsn = url.parse(process.env.CLEARDB_DATABASE_URL)\r\n    , parseError = function(msg) {\r\n        return new Error('[CLEARDB_DATABASE_URL] '+msg);\r\n      };\r\n\r\n  if(dsn.protocol != 'mysql:') {\r\n    throw parseError('Scheme must be mysql');\r\n  }\r\n  if(!dsn.auth) {\r\n    throw parseError('No credencials');\r\n  }\r\n\r\n  var auth = dsn.auth.split(':');\r\n  if(auth.length != 2) {\r\n    throw parseError('Invalid credencials');\r\n  }\r\n\r\n  if(!dsn.pathname || dsn.pathname == '\/') {\r\n    throw parseError('No database name');\r\n  }\r\n\r\n  var path = dsn.pathname.split('\/');\r\n  if(path.length != 2) {\r\n    throw parseError('Invalid database name');\r\n  }\r\n  path.shift();\r\n\r\n  var config = {\r\n      database: path.shift()\r\n    , username: auth.shift()\r\n    , password: auth.shift()\r\n    , options:  { dialect: 'mysql' }\r\n  };\r\n\r\n  if(dsn.hostname) {\r\n    config.options.host = dsn.hostname;\r\n  }\r\n  if(dsn.port) {\r\n    config.options.port = dsn.port;\r\n  }\r\n\r\n  return config;\r\n}\r\n<\/pre>\n<p>\u304b\u306a\u308a\u57f7\u62d7\u306a\u30a8\u30e9\u30fc\u30c1\u30a7\u30c3\u30af\u3092\u3057\u3066\u3044\u308b\u304c\u3001\u3053\u308c\u306fSequelize\u3092heroku\u306eClearDB\u3068\u9023\u643a\u3055\u305b\u308b\u3068\u304d\u306b\u3001<a href=\"http:\/\/h2plus.biz\/hiromitsu\/entry\/631\">node.js\u3067Sequelize\u3092\u4f7f\u3046\u305f\u3081\u306e\u6e96\u5099\uff0f\u524d\u7de8<\/a>\u3067\u7d39\u4ecb\u3057\u305f<code>dbconn<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u6d41\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u66f8\u3044\u305f\u3082\u306e\u3002<\/p>\n<p>\u6539\u826f\u3057\u305f<code>dbconn<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u672c\u4f53\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"brush: jscript; first-line: 9; highlight: [13,15,16,17,18]; title: ; notranslate\" title=\"\">\r\nmodule.exports = function(config) {\r\n\r\n  var Sequelize = require('sequelize')\r\n    , params = config.sequelize || {}\r\n    , cleardb = parseClearDbUrl();\r\n\r\n  if(cleardb != null) {\r\n    var extend = require('node.extend');\r\n    params = extend(params, cleardb);\r\n  }\r\n  params.options = params.options || {};\r\n\r\n  console.log('Sequelize connecting to %s on %s as %s', params.database, params.options.host || 'localhost', params.username);\r\n  return new Sequelize(params.database, params.username, params.password, params.options);\r\n};};\r\n<\/pre>\n<p>\u4eca\u56de\u306e\u53c2\u52a0\u8005\u306f\u307f\u3093\u306a\u884c\u5100\u3088\u304f\u30ac\u30a4\u30c9\u306b\u5f93\u3063\u3066\u4f5c\u696d\u3092\u3057\u3066\u3044\u304f\u611f\u3058\u3067\u3001\u81ea\u5206\u3067\u65b0\u3057\u3044\u9053\u3092\u958b\u62d3\u3057\u3066\u3044\u304f\uff08\u8131\u7dda\u3068\u3082\u3044\u3046\uff09\u30d7\u30ed\u30b0\u30e9\u30de\u304c\u73fe\u308c\u306a\u304b\u3063\u305f\u306e\u304c\u3061\u3087\u3063\u3068\u6b8b\u5ff5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>7\u670820\u65e5\u306b\u50ac\u3055\u308c\u305fJTPA\u30ae\u30fc\u30af\u30b5\u30ed\u30f3\u300c\u9752\u6728\u6df3\u6c0f\u3068Node.js\/Heroku\u3092\u4f53\u9a13\u3059\u308b\u300d\u306b\u30dc\u30e9\u30f3\u30c6\u30a3\u30a2\u306e\u30c6\u30af\u30cb\u30ab\u30eb\u30b5\u30dd\u30fc\u30c8\u30b9\u30bf\u30c3\u30d5\u3068\u3057\u3066\u53c2\u52a0\u3057\u3066\u304d\u305f\u3002JTPA\u3067\u306e\u30cf\u30c3\u30ab\u30bd\u30f3\u306f\u3001Hadoop\u3067\u59cb\u3081\u308b\u4e26\u5217\u30c7\u30fc\u30bf\u89e3\u6790\u4ee5\u6765\u3002 <a href='https:\/\/h2plus.biz\/hiromitsu\/entry\/686' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[77,11],"tags":[239,240,82,238,139,237],"_links":{"self":[{"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/posts\/686"}],"collection":[{"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/comments?post=686"}],"version-history":[{"count":3,"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/posts\/686\/revisions"}],"predecessor-version":[{"id":1000,"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/posts\/686\/revisions\/1000"}],"wp:attachment":[{"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/media?parent=686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/categories?post=686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h2plus.biz\/hiromitsu\/wp-json\/wp\/v2\/tags?post=686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}