{"id":11734,"date":"2017-09-21T10:00:57","date_gmt":"2017-09-21T01:00:57","guid":{"rendered":"http:\/\/sitest.jp\/blog\/?p=11734"},"modified":"2017-09-19T20:27:14","modified_gmt":"2017-09-19T11:27:14","slug":"node-js%e3%81%ae%e8%bb%bd%e9%87%8fweb%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%83%af%e3%83%bc%e3%82%afexpress-js%e3%81%ae%e5%b0%8e%e5%85%a5%e3%81%a8%e6%8b%a1%e5%bc%b5","status":"publish","type":"post","link":"https:\/\/sitest.jp\/blog\/?p=11734","title":{"rendered":"Node.js\u306e\u8efd\u91cfweb\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30afExpress.js\u306e\u5c0e\u5165\u3068\u62e1\u5f35"},"content":{"rendered":"<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">Express \u3068\u306f<\/h3>\n<\/div>\n<p>Express \u3068\u306f node.js \u306e\u8efd\u91cf web \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002<br \/>\nnode.js \u306e web \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u4e2d\u3067\u3082\u6700\u3082\u6709\u540d\u306a\u3082\u306e\u3067\u3059\u3002<br \/>\nMEAN \u30b9\u30bf\u30c3\u30af \u306e\u300cE\u300d\u306e\u7b87\u6240\u3068\u8a00\u3048\u3070\u6709\u540d\u306a\u306e\u304c\u4f1d\u308f\u308a\u307e\u3059\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u3068\u3063\u3064\u304d\u3084\u3059\u304f\u3001\u305d\u308c\u6545\u306b\u62e1\u5f35\u6027\u3082\u9ad8\u3044\u3067\u3059\u3002<br \/>\n\u307e\u305f\u6709\u540d\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3082\u3042\u308b\u306e\u3067\u304b\u306a\u308a\u306e\u60c5\u5831\u304c\u898b\u3064\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u30b5\u30fc\u30d0\u30fc\u8d77\u52d5<\/h3>\n<\/div>\n<p>\u307e\u305a module \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><code>npm install express\n<\/code><\/pre>\n<p>js\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057 module \u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre><code>var express = require(\u2018express\u2019);\n<\/code><\/pre>\n<p>\u547c\u3073\u51fa\u3055\u308c\u305f express \u30e1\u30bd\u30c3\u30c9 \u3092\u5b9f\u884c\u3059\u308c\u3070\u6e96\u5099\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u3068\u308a\u3042\u3048\u305a8888\u30dd\u30fc\u30c8\u3092 listen \u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>var app = express();\nvar server = app.listen(8888);\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u3067\u30b5\u30fc\u30d0\u30fc\u8d77\u52d5\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u3042\u3068\u306f\u3000app\u3000\u306b\u5bfe\u3057\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3057\u3066\u3044\u304f\u3053\u3068\u3067 web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u4f5c\u308c\u307e\u3059\u3002<br \/>\n\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b http \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u3063\u305f\u5834\u5408\u3082\u540c\u3058\u3088\u3046\u306a\u624b\u9806\u3067\u30b5\u30fc\u30d0\u30fc\u8d77\u52d5\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>var http = require('http');\nvar server = http.createServer();\n\nserver.listen(8888);\n<\/code><\/pre>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u306e\u914d\u4fe1<\/h3>\n<\/div>\n<p>\u7d9a\u3044\u3066\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u306e\u914d\u4fe1\u3092\u8a2d\u5b9a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3063\u3066\u3082\u30011\u884c\u3067\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\napp.listen \u306e\u624b\u524d\u306b\u4e0b\u8a18\u306e\u8a18\u8ff0\u3067\u5b9f\u88c5\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre><code>app.use(express.static(\u2018.\/public\u2019));\n<\/code><\/pre>\n<p>\u3053\u308c\u3067 public \u4ee5\u4e0b\u306b\u914d\u7f6e\u3055\u308c\u305f\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u3078\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0<\/h3>\n<\/div>\n<p>Express \u306e\u62e1\u5f35\u306f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u547c\u3070\u308c\u308b\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306f\u30ea\u30af\u30a8\u30b9\u30c8( req )\u3068\u30ec\u30b9\u30dd\u30f3\u30b9 ( res ) \u306b\u5bfe\u3057\u8aad\u307f\u53d6\u308a\u3001\u66f8\u304d\u63db\u3048\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u7279\u5b9a\u306e\u30eb\u30fc\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304d\u305f\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3057\u7279\u5b9a\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u51e6\u7406\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>log_hoge = function(req, res, next){\n  console.log(\u2018hoge\u2019);\n  next();\n}\n<\/code><\/pre>\n<p>\u3053\u308c\u3067 log_hoge \u3068\u3044\u3046\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u304c\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u306f app \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e use \u30e1\u30bd\u30c3\u30c9\u3067\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u6307\u5b9a\u3057\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>app.use(log_hoge);\n<\/code><\/pre>\n<p>\u3053\u308c\u3067\u5148\u7a0b\u8a2d\u5b9a\u3057\u305f\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u306b\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068 hoge \u3068\u3044\u3046\u6587\u5b57\u304c\u30b5\u30fc\u30d0\u30fc\u5074\u3067\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u7d9a\u3044\u3066\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3067\u3059\u3002<br \/>\n\u73fe\u6642\u70b9\u3067\u306f\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u304b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u8a2d\u5b9a\u3059\u308b\u306b\u306f app \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5404\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre><code>app.get(\u2018\/fuga\u2019, function (req, res) {\n  res.send(\u2018fuga requested!\u2019);\n});\n<\/code><\/pre>\n<p>\u3053\u308c\u3067 GET \u30e1\u30bd\u30c3\u30c9\u3067 \/fuga \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u30d6\u30e9\u30a6\u30b6\u3067 \u300cfuga requested!\u300d\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3059\u308b URL \u6bce\u306b\u3069\u306e\u3088\u3046\u306a\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u306e\u304b\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3 jade \u306e\u5229\u7528<\/h3>\n<\/div>\n<p>Express \u3067\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u6307\u5b9a\u3057\u3066\u304a\u304f\u3053\u3068\u3067<br \/>\n\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3067\u4f5c\u6210\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u914d\u4fe1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3042\u3089\u304b\u3058\u3081 module \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre><code>npm install jade\n<\/code><\/pre>\n<pre><code>var data = {title: \u201cpiyo\u201d};\n\napp.set('view engine', 'jade');\napp.get('\/', function (req, res) {\n  res.render('index', data);\n});\n<\/code><\/pre>\n<p>\u3042\u3068\u306f views \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4e2d\u306b\u8a72\u5f53\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308c\u3070<br \/>\nhtml \u3068\u3057\u3066\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f data \u306b\u306f\u5165\u308c\u305f\u5024\u306f jade \u5074\u3067\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u5185\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u308a\u3001\u5225\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u3046\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u304f\u308c\u3070\u57fa\u672c\u7684\u306a web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u5b9f\u88c5\u3067\u304d\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n<p>\u4e00\u70b9\u6c17\u3092\u4ed8\u3051\u308b\u5fc5\u8981\u304c\u3042\u308b\u70b9\u3068\u3057\u3066\u3001\u307b\u307c\u3059\u3079\u3066\u306e\u51e6\u7406\u304c\u975e\u540c\u671f\u3067\u5b9f\u884c\u3055\u308c\u308b\u305f\u3081\u304b\u306a\u308a\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u304c\u30cd\u30b9\u30c8\u3055\u308c\u308b\u70b9\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e next \u95a2\u6570\u7b49\u3082\u8a2d\u5b9a\u3057\u3066\u304a\u304b\u306a\u3044\u3068\u63a5\u7d9a\u304c\u30cf\u30f3\u30b0\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u307e\u3068\u3081<\/h3>\n<\/div>\n<p>Node.js \u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u975e\u5e38\u306b\u30e1\u30b8\u30e3\u30fc\u306a Express.js \u306e\u6982\u8981\u3068\u62e1\u5f35\u306e\u624b\u6bb5\u306b\u3064\u3044\u3066\u66f8\u304b\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002<br \/>\n\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306f\u4e0a\u8a18\u306e\u3088\u3046\u306b\u81ea\u5206\u3067\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3057\u3001\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u88fd\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092 npm \u7b49\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u5229\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4ed6\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u6bd4\u8f03\u3057\u305f\u6642\u8a18\u8ff0\u3059\u308b\u9805\u76ee\u304c\u591a\u3044\u3067\u3059\u304c\u3001\u305d\u306e\u5206\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u6027\u304c\u9ad8\u304f\u5fdc\u7528\u304c\u5229\u304d\u307e\u3059\u3002<\/p>\n<p>\u65e5\u672c\u8a9e\u306e\u60c5\u5831\u3082\u591a\u3044\u306e\u3067\u3001Node.js \u3067\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3063\u3066\u307f\u308b\u5834\u5408\u306f\u307e\u305a Express.js \u304c\u697d\u306b\u4f7f\u3048\u5f8c\u306e\u62e1\u5f35\u3082\u30b9\u30e0\u30fc\u30ba\u306b\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Express \u3068\u306f Express \u3068\u306f node.js \u306e\u8efd\u91cf web \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002 node.js \u306e web \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u4e2d\u3067\u3082\u6700\u3082\u6709\u540d\u306a\u3082\u306e\u3067\u3059\u3002 MEAN \u30b9\u30bf\u30c3\u30af \u306e\u300cE\u300d\u306e\u7b87\u6240\u3068\u8a00\u3048\u3070\u6709\u540d\u306a\u306e\u304c\u4f1d\u308f\u308a\u307e\u3059\u3067\u3057\u3087\u3046\u304b\uff1f \u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u3068\u3063\u3064\u304d\u3084\u3059\u304f\u3001\u305d\u308c\u6545\u306b\u62e1\u5f35\u6027\u3082\u9ad8\u3044\u3067\u3059\u3002 \u307e\u305f\u6709\u540d\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3082\u3042\u308b\u306e\u3067\u304b\u306a\u308a\u306e\u60c5\u5831\u304c\u898b\u3064\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"author":3,"featured_media":11738,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[51,37,27],"tags":[],"acf":false,"_links":{"self":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11734"}],"collection":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/comments?post=11734"}],"version-history":[{"count":7,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11734\/revisions"}],"predecessor-version":[{"id":13155,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11734\/revisions\/13155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media\/11738"}],"wp:attachment":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media?parent=11734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/categories?post=11734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/tags?post=11734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}