{"id":5485,"date":"2020-01-07T19:49:02","date_gmt":"2020-01-07T10:49:02","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=5485"},"modified":"2020-02-04T00:20:17","modified_gmt":"2020-02-03T15:20:17","slug":"%e5%85%a5%e9%96%80%ef%bc%81express%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%a8%e5%9f%ba%e6%9c%ac%e3%81%ae%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=5485","title":{"rendered":"\u5165\u9580\uff01Express\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u57fa\u672c\u306e\u307e\u3068\u3081"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u307e\u3067\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306f<code>Laravel<\/code>\u3084<code>Vue<\/code>\u306e\u8a18\u4e8b\u3092\u591a\u304f\u516c\u958b\u3057\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u306e\u5ea6\u300c<strong>\u3088\u308a\u9ad8\u901f\u306b\u52d5\u304f\u30b5\u30a4\u30c8<\/strong>\u300d\u3092\u958b\u767a\u3059\u308b\u53ef\u80fd\u6027\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001\u3053\u308c\u307e\u3067\u864e\u8996\u7708\u3005\u3068\u72d9\u3063\u3066\u3044\u305f<code>Node.js<\/code>\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u300c<strong>Express<\/strong>\u300d\u3082\u5c11\u3057\u305a\u3064\u8a18\u4e8b\u3068\u3057\u3066\u7d39\u4ecb\u3057\u3066\u3044\u3051\u305f\u3089\u306a\u3001\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002\uff08\u3068\u3044\u3063\u3066\u3082\u30e1\u30a4\u30f3\u306f\u5927\u597d\u304d\u306a<code>Laravel<\/code>\u3067\u4e0d\u52d5\u3067\u3059\u304c\ud83d\ude0a\uff09<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f\u3001\u307e\u305a\u306f<code>Express<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5\u3068\u3001\u3055\u3089\u306b\u3001<code>Express<\/code>\u3092\u4f7f\u3046\u57fa\u672c\u7684\u306a\u5185\u5bb9\u3092\u307e\u3068\u3081\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2173 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png\" alt=\"\" width=\"300\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24-281x300.png 281w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Node.js 8.10\u3001Ubuntu 18.04\u3001nginx 1.14<\/p>\n<h1>\u30d5\u30a9\u30eb\u30c0\u3092\u7528\u610f\u3059\u308b<\/h1>\n<p>\u307e\u305a<code>Express<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u30d5\u30a9\u30eb\u30c0\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5489\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_3.png\" alt=\"\" width=\"263\" height=\"126\" \/><\/p>\n<p>\u203b \u30d5\u30a9\u30eb\u30c0\u540d\u306f\u304a\u597d\u307f\u3067\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>Express\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306b\uff08<code>cd<\/code>\u30b3\u30de\u30f3\u30c9\u3067\uff09\u79fb\u52d5\u3057\u3001\u4ee5\u4e0b\u306e<span style=\"font-size: 1rem;\">\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066<\/span><code>npm<\/code><span style=\"font-size: 1rem;\">\u3092\u521d\u671f\u5316\u3057\u307e\u3059\u3002<\/span><\/p>\n<pre><strong>npm init<\/strong><\/pre>\n<p>\u203b \u8272\u3005\u3068\u8cea\u554f\u3055\u308c\u307e\u3059\u304c\u3001\u3081\u3093\u3069\u3046\u306a\u5834\u5408\u306f<code>Enter<\/code>\u30ad\u30fc\u9023\u6253\u3067\u7d42\u4e86\u3055\u305b\u308b\u304b<code>-y<\/code>\u3092\u3064\u3051\u3066\u8cea\u554f\u3092\u30b9\u30ad\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u6b21\u306b<code>Express<\/code>\u306e\u672c\u4f53\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>npm install express --save<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3059\u308b\u3068\u30d5\u30a9\u30eb\u30c0\u5185\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5492\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_6.png\" alt=\"\" width=\"361\" height=\"146\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_6.png 361w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_6-300x121.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><\/p>\n<h1>\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u7528\u306e\u30b3\u30fc\u30c9\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u3001\u30d6\u30e9\u30a6\u30b6\u304b\u3089<code>Express<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u304c\u8d77\u52d5\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u300c<strong>package.json<\/strong>\u300d\u3092\u958b\u3044\u3066\u300c<strong>scripts &gt; start<\/strong>\u300d\u306e\u90e8\u5206\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>{\r\n  \"name\": \"express41\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"\",\r\n  \"main\": \"index.js\",\r\n  \"scripts\": {\r\n    <strong>\"start\": \"nodejs app.js\"<\/strong>\r\n  },\r\n  \"author\": \"\",\r\n  \"license\": \"ISC\",\r\n  \"dependencies\": {\r\n    \"express\": \"^4.17.1\"\r\n  }\r\n}<\/pre>\n<p>\u203b <strong>\u6ce8\u610f\uff1a<\/strong><code>Ubuntu<\/code>\u306e\u5834\u5408<code>Node.js<\/code>\u306e\u30b3\u30de\u30f3\u30c9\u306f<code>node<\/code>\u3067\u306f\u306a\u304f<code>nodejs<\/code>\u3067\u3059\u3002\u3082\u3057<code>node<\/code>\u3067\u5b9f\u884c\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u3092\u4f5c\u3063\u3066\u304a\u304f\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>sudo ln -s \"$(which nodejs)\" \/usr\/bin\/node<\/strong><\/pre>\n<p>\u7d9a\u3044\u3066\u3001\u540c\u3058\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u300c<strong>app.js<\/strong>\u300d\u3092\u4f5c\u6210\u3057\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>const express = require('express');\r\nconst app = express();\r\n\r\napp.get('\/', (req, res) =&gt; {\r\n  res.send('\u3046\u307e\u304f\u52d5\u3044\u3066\u307e\u3059\uff01');\r\n});\r\n\r\n\/\/ 5000\u756a\u30dd\u30fc\u30c8\u3067\u5f85\u6a5f\r\nconst PORT = process.env.PORT || 5000;\r\napp.listen(PORT, () =&gt; {\r\n  console.log(`${PORT}\u756a\u306e\u30dd\u30fc\u30c8\u3067\u5f85\u6a5f\u4e2d\u3067\u3059...`);\r\n});\r\n<\/strong><\/pre>\n<p>\u7d9a\u3044\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066<code>npm<\/code>\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>npm start<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8868\u793a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5514\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_8.png\" alt=\"\" width=\"587\" height=\"140\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_8.png 587w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_8-300x72.png 300w\" sizes=\"auto, (max-width: 587px) 100vw, 587px\" \/><\/p>\n<p>\u3053\u308c\u3067\u3001\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u306e\u8a2d\u5b9a\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u300c<strong>http:\/\/localhost:5000<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5495\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_9.png\" alt=\"\" width=\"287\" height=\"79\" \/><\/p>\n<h1>\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3\u3092\u3064\u304b\u3046<\/h1>\n<p>\u3082\u3061\u308d\u3093\u3053\u306e\u307e\u307e\u958b\u767a\u3092\u9032\u3081\u3066\u3082\u3044\u3044\u3067\u3057\u3087\u3046\u304c\u3001\u300c<strong>localhost:5000<\/strong>\u300d\u3067\u306f\u958b\u767a\u3059\u308b\u30b5\u30a4\u30c8\u304c\u5897\u3048\u3066\u304f\u308b\u3068\u3001\u3069\u308c\u304c\u3069\u306e\u30b5\u30a4\u30c8\u304b\u308f\u304b\u3089\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u300c<strong>http:\/\/express41.test<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u4eca\u56de\u4f5c\u3063\u305f<code>Express<\/code>\u30a2\u30d7\u30ea\u304c\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001\u300c<strong>\/etc\/nginx\/sites-available\/default<\/strong>\u300d\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>server {\r\n    listen 80;\r\n    server_name express41.test;\r\n    location \/ {\r\n        proxy_pass http:\/\/localhost:5000;\r\n        proxy_http_version 1.1;\r\n        proxy_set_header Upgrade $http_upgrade;\r\n        proxy_set_header Connection 'upgrade';\r\n        proxy_set_header Host $host;\r\n        proxy_cache_bypass $http_upgrade;\r\n        proxy_set_header X-Forwarded-For $remote_addr;\r\n     }\r\n}<\/strong><\/pre>\n<p>\u3010\u8ffd\u8a18\uff1a2020.02.04\u3011IP\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u6700\u5f8c\u306e\u884c\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u304c\u306a\u3044\u3068\u5168\u3066\u30ed\u30fc\u30ab\u30eb\u304b\u3089\u306e\u63a5\u7d9a\u306b\u306a\u308b\u306e\u3067\u300c::ffff:127.0.0.1\u300d\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u306a\u304aIP\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;<\/strong><\/pre>\n<p>\u4fdd\u5b58\u3057\u305f\u3089<code>nginx<\/code>\u3092\u518d\u8d77\u52d5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>sudo systemctl restart nginx<\/strong><\/pre>\n<p>\u6b21\u306b\u300c<strong>express41.test<\/strong>\u300d\u304c\u30ed\u30fc\u30ab\u30eb\u306b\u5411\u304f\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b \u3053\u3053\u304b\u3089\u306f\u300c<strong>windows 10\u7de8<\/strong>\u300d\u3068\u300c<strong>Ubuntu 18.04\u7de8<\/strong>\u300d\u306b\u5225\u308c\u307e\u3059\u3002\u3054\u81ea\u8eab\u306e\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u8aad\u307f\u9032\u3081\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u30fb\u30fb\u30fb\u3068\u3044\u3063\u3066\u3082\u3001\u307b\u3068\u3093\u3069win 10\u3060\u3068\u601d\u3044\u307e\u3059\u304c\ud83d\ude05\uff09<\/p>\n<h2>Windows 10\u7de8<\/h2>\n<p>\u307e\u305a\u3001\u691c\u7d22\u30dc\u30c3\u30af\u30b9\u306b\u300c<strong>notepad<\/strong>\u300d\u3068\u5165\u529b\u3057\u3066\u30e1\u30e2\u5e33\u3092\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5507\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_10.png\" alt=\"\" width=\"392\" height=\"680\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_10.png 392w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_10-173x300.png 173w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/p>\n<p>\u305d\u306e\u307e\u307e\u30af\u30ea\u30c3\u30af<strong>\u305b\u305a<\/strong>\u3001\u53f3\u30af\u30ea\u30c3\u30af\u3092\u3057\u3066\u300c<strong>\u7ba1\u7406\u8005\u3068\u3057\u3066\u5b9f\u884c<\/strong>\u300d\u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5506\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_11.png\" alt=\"\" width=\"344\" height=\"209\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_11.png 344w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_11-300x182.png 300w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/p>\n<p>\u78ba\u8a8d\u306e\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u300c\u306f\u3044\u300d\u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5505\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_12.png\" alt=\"\" width=\"456\" height=\"316\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_12.png 456w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_12-300x208.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/p>\n<p>\u30e1\u30e2\u5e33\u304c\u8d77\u52d5\u3059\u308b\u306e\u3067\u3001\u300c<strong>\u30d5\u30a1\u30a4\u30eb &gt; \u958b\u304f<\/strong>\u300d\u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5504\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_13.png\" alt=\"\" width=\"309\" height=\"239\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_13.png 309w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_13-300x232.png 300w\" sizes=\"auto, (max-width: 309px) 100vw, 309px\" \/><\/p>\n<p>\u300c<strong>c:\\Windows\\System32\\Drivers\\etc<\/strong>\u300d\u3092\u9078\u629e \u3059\u308b\u3068\uff08\u304a\u305d\u3089\u304f\uff09\u4f55\u3082\u8868\u793a\u3055\u308c\u306a\u3044\u306e\u3067\u3001\u53f3\u4e0b\u306e\u8868\u793a\u30d5\u30a1\u30a4\u30eb\u30bf\u30a4\u30d7\u3092\u300c<strong>\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb<\/strong>\u300d\u306b\u5909\u66f4\u3057\u3001\u300c<strong>hosts<\/strong>\u300d\u3092\u958b\u304f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5503\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_14.png\" alt=\"\" width=\"626\" height=\"473\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_14.png 626w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_14-300x227.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/p>\n<p>\u6700\u7d42\u884c\u306b\u300c<strong>127.0.0.1 express41.test<\/strong>\u300d\u3092\u8ffd\u52a0\u3057\u3066\u4fdd\u5b58\u3059\u308b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5502\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_15.png\" alt=\"\" width=\"465\" height=\"74\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_15.png 465w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_15-300x48.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/p>\n<h3>Ubuntu\u7de8<\/h3>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>sudo gedit \/etc\/hosts<\/strong><\/pre>\n<p>\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u304c\u958b\u304f\u306e\u3067\u3001<\/p>\n<pre><strong>127.0.1.1\texpress41.test<\/strong><\/pre>\n<p>\u3092\u8ffd\u52a0\u3057\u3066\u4fdd\u5b58\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u30d6\u30e9\u30a6\u30b6\u3067\u78ba\u304b\u3081\u308b<\/h2>\n<p>\u3067\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u300c<strong>http:\/\/express41.test<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5508\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_16.png\" alt=\"\" width=\"454\" height=\"83\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_16.png 454w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_16-300x55.png 300w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/p>\n<h1>\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u300cpublic\u300d\u30d5\u30a9\u30eb\u30c0\u3092\u3064\u304f\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u753b\u50cf\u3084<code>HTML<\/code>\u3001<code>CSS<\/code>\u3001\uff08\u30d6\u30e9\u30a6\u30b6\u5074\u306e\uff09<code>JS<\/code>\u30d5\u30a1\u30a4\u30eb\u306b\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u753b\u50cf\u3092\u4f7f\u3044\u307e\u3059\u3002\uff08\u795e\u6238\u30dd\u30fc\u30c8\u30bf\u30ef\u30fc\u8fd1\u304f\u306b\u5c55\u793a\u3055\u308c\u3066\u3044\u308b\u30af\u30ea\u30b9\u30bf\u30eb\u30fb\u30d4\u30a2\u30ce\u3067\u3059\ud83d\ude0a\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5510\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/crystal_piano.jpg\" alt=\"\" width=\"300\" height=\"400\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/crystal_piano.jpg 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/crystal_piano-225x300.jpg 225w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u3067\u306f\u3001\u307e\u305a\u306f\u300c<strong>\/public\/images<\/strong>\u300d\u30d5\u30a9\u30eb\u30c0\u3092\u3064\u304f\u3063\u3066\u3001\u305d\u3053\u306b\u300c<strong>crystal_piano.jpg<\/strong>\u300d\u3092\u8a2d\u7f6e\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5512\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_17.png\" alt=\"\" width=\"455\" height=\"142\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_17.png 455w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_17-300x94.png 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><\/p>\n<p>\u6b21\u306b\u3001\u300c<strong>app.js<\/strong>\u300d\u3067\u300c<strong>public<\/strong>\u300d\u30d5\u30a9\u30eb\u30c0\u306b\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>const express = require('express');\r\nconst app = express();\r\n\r\napp.get('\/', (req, res) =&gt; {\r\n  res.send('\u3046\u307e\u304f\u52d5\u3044\u3066\u307e\u3059\uff01');\r\n});\r\n\r\n<strong>\/\/ \u3053\u3053\u2193\u2193\u2193\r\napp.use(express.static('public'));<\/strong>\r\n\r\n\/\/ 5000\u756a\u30dd\u30fc\u30c8\u3067\u5f85\u6a5f\r\nconst PORT = process.env.PORT || 5000;\r\napp.listen(PORT, () =&gt; {\r\n  console.log(`${PORT}\u756a\u306e\u30dd\u30fc\u30c8\u3067\u5f85\u6a5f\u4e2d\u3067\u3059...`);\r\n});<\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u3053\u3053\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u304c\u3001\u300c<strong>app.js<\/strong>\u300d\u306b\u5909\u66f4\u3092\u52a0\u3048\u305f\u5834\u5408\u306f\u5fc5\u305a<code>npm<\/code>\u3092\u518d\u8d77\u52d5\u3057\u306a\u3044\u3068\u3044\u3051\u3044\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u300cCtrl+C\u300d\u306a\u3069\u3067\u30b9\u30c8\u30c3\u30d7\u3057\u3066\u3082\u3046\u4e00\u5ea6\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u306a\u3044\u3068\u5909\u66f4\u7b87\u6240\u304c\u53cd\u6620\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre><strong>npm start<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u300c<strong>http:\/\/express41.test\/images\/crystal_piano.jpg<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u300c<strong>public\/images\/crystal_piano.jpg<\/strong>\u300d\u306e\u753b\u50cf\u304c\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08URL\u306b\u306f<code>public<\/code>\u306f\u4e0d\u8981\u3067\u3059\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<h1>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u306f<code>express41<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092<code>MySQL<\/code>\u3067\u7528\u610f\u3057\u3066\u3001\u305d\u3053\u304b\u3089\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<code>mysql<\/code>\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>npm install mysql<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001<code>MySQL<\/code>\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u308a\u3001\u30c6\u30b9\u30c8\u3068\u3057\u3066<code>users<\/code>\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5518\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_18.png\" alt=\"\" width=\"369\" height=\"297\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_18.png 369w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_18-300x241.png 300w\" sizes=\"auto, (max-width: 369px) 100vw, 369px\" \/><\/p>\n<p>\u203b \u306a\u304a\u3001DB\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u306f<code>Laravel<\/code>\u3068\u540c\u3058\u304f <code>utf8mb4_unicode_ci<\/code>\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30c6\u30b9\u30c8\u7528\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3082\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5519\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_19.png\" alt=\"\" width=\"516\" height=\"359\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_19.png 516w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_19-300x209.png 300w\" sizes=\"auto, (max-width: 516px) 100vw, 516px\" \/><\/p>\n<p>\u7d9a\u3044\u3066\u3001\u3053\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u30eb\u30fc\u30c8\u30d5\u30a9\u30eb\u30c0\u306b\u300c<strong>db.js<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>const mysql = require('mysql');\r\nconst db = mysql.createConnection({\r\n    host     : '127.0.0.1',\r\n    user     : 'root',       \/\/ DB\u63a5\u7d9a\u30e6\u30fc\u30b6\u30fc\r\n    password : '**********', \/\/ DB\u63a5\u7d9a\u30d1\u30b9\u30ef\u30fc\u30c9\r\n    database : 'express41'\r\n});\r\n\r\ndb.connect(err =&gt; {\r\n\r\n    if(err) { \/\/ DB\u306e\u63a5\u7d9a\u306b\u5931\u6557\r\n\r\n      throw err;\r\n\r\n    };\r\n\r\n});\r\n\r\nmodule.exports = db;<\/strong><\/pre>\n<p>\u3067\u306f\u3001\u300c<strong>app.js<\/strong>\u300d\u306b\u623b\u3063\u3066<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\uff08<strong>\u592a\u5b57<\/strong>\u304c\u8ffd\u52a0\u3057\u305f\u90e8\u5206\u3067\u3059\uff09<\/p>\n<pre>const express = require('express');\r\nconst app = express();\r\n<strong>const db = require('.\/db');<\/strong>\r\n\r\n<strong>app.get('\/', (req, res) =&gt; {\r\n\r\n  const sql = 'SELECT * FROM users';\r\n  db.query(sql, (err, rows) =&gt; {\r\n\r\n    if(rows.length &gt; 0) { \/\/ \u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u3063\u305f\u5834\u5408\r\n\r\n      res.send(rows);\r\n\r\n    } else {\r\n\r\n      res.send('\u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002');\r\n\r\n    }\r\n\r\n  });\r\n\r\n});<\/strong>\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3053\u306e\u72b6\u614b\u3067\u300c<strong>http:\/\/express41.test<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bDB\u30c7\u30fc\u30bf\u304c<code>JSON<\/code>\u5f62\u5f0f\u3067\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>[{\"id\":1,\"name\":\"\u592a\u90ce\",\"email\":\"taro@example.com\"},<\/strong>\uff08\u7701\u7565\uff09<strong>}]\r\n<\/strong><\/pre>\n<h1>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3092\u3064\u304b\u3046<\/h1>\n<p><code>Express<\/code>\u306f\u591a\u6570\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u306e<code>Blade<\/code>\u306b\u8fd1\u3044<code>mustache.js<\/code>\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>npm install mustache-express --save<\/strong><\/pre>\n<p>\u6b21\u306b\u3001\u300c<strong>app.js<\/strong>\u300d\u3067\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u306e\u8a2d\u5b9a\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre>const express = require('express');\r\nconst app = express();\r\nconst db = require('.\/db');\r\n\r\n<strong>\/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\r\nconst mustacheExpress = require('mustache-express');\r\napp.engine('mst', mustacheExpress());\r\napp.set('view engine', 'mst');\r\napp.set('views', __dirname + '\/views');\r\n\r\napp.get('\/', (req, res) =&gt; {\r\n\r\n  res.render('index', {\r\n    title: '\u30da\u30fc\u30b8\u30bf\u30a4\u30c8\u30eb',\r\n    message: '\u30c6\u30b9\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8'\r\n  });\r\n\r\n});\r\n\r\n<\/strong>\/\/ \u7701\u7565<\/pre>\n<p>\u3053\u308c\u3067\u3001<code>views<\/code>\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b\u3042\u308b<code>.mst<\/code>\u3068\u3044\u3046\u62e1\u5f35\u5b50\u304c\u3064\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u304c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u300c<strong>\/views\/index.mst<\/strong>\u300d\u3092\u4f5c\u6210\u3057\u3066\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;!DOCTYPE HTML&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;title&gt;<strong>{{ title }}<\/strong>&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n  &lt;div&gt;\r\n    <strong>{{ message }}<\/strong>\r\n  &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3067\u306f\u3001\u3053\u306e\u72b6\u614b\u3067\u3082\u3046\u4e00\u5ea6\u300c<strong>npm start<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u518d\u8d77\u52d5\u3057\u3066\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5520\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_20.png\" alt=\"\" width=\"441\" height=\"80\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_20.png 441w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_20-300x54.png 300w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/p>\n<h2>\u914d\u5217\u3092\u30eb\u30fc\u30d7\u3059\u308b<\/h2>\n<p><code>mustache.js<\/code>\u3067\u914d\u5217\u3092\u30eb\u30fc\u30d7\u3059\u308b\u306b\u306f\u3001\u307e\u305a\u914d\u5217\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<pre>res.render('index', {\r\n    <strong>numbers: [1, 2, 3, 4, 5]<\/strong>\r\n});<\/pre>\n<p>\u305d\u3057\u3066\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30d5\u30a1\u30a4\u30eb\u306e\u65b9\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u30eb\u30fc\u30d7\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>{{ #numbers }}<\/strong>\r\n<strong>    &lt;ul&gt;<\/strong>\r\n<strong>      &lt;li&gt;{{ . }}&lt;\/li&gt;<\/strong>\r\n<strong>    &lt;\/ul&gt;<\/strong>\r\n<strong>{{ \/numbers }}<\/strong><\/pre>\n<h2>\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u30eb\u30fc\u30d7\u3059\u308b<\/h2>\n<p><code>mustache.js<\/code>\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u914d\u5217\u3068\u3057\u3066\u307e\u3068\u307e\u3063\u305f\u3001\u3044\u308f\u3086\u308b\u300c\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u300d\u3092\u30eb\u30fc\u30d7\u3059\u308b\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<pre>res.render('index', {\r\n    <strong>users: [<\/strong>\r\n<strong>        {name: '\u540d\u524d\uff11', email: 'test1@example.com'},<\/strong>\r\n<strong>        {name: '\u540d\u524d\uff12', email: 'test2@example.com'},<\/strong>\r\n<strong>        {name: '\u540d\u524d\uff13', email: 'test2@example.com'},<\/strong>\r\n<strong>    ]<\/strong>\r\n});<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4e2d\u3067\u306e\u30eb\u30fc\u30d7\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>{{ #users }}\r\n&lt;ul&gt;\r\n    &lt;li&gt;<strong>{{ name }}<\/strong>: <strong>{{ email }}<\/strong>&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n{{ \/users }}<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5521\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_21.png\" alt=\"\" width=\"292\" height=\"130\" \/><\/p>\n<h1>\u30eb\u30fc\u30c8\u3092\u5206\u5272\u3059\u308b<\/h1>\n<p>\u3053\u3053\u307e\u3067\u3067\u306f\u3001\u300c<strong>app.js<\/strong>\u300d\u5185\u306b\u30eb\u30fc\u30c8\u3092\u4f5c\u3063\u3066\u5b9f\u884c\u3057\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u958b\u767a\u3092\u9032\u3081\u3066\u3044\u304f\u4e0a\u3067\u3001\u3055\u3059\u304c\u306b\u5168\u3066\u306e\u30eb\u30fc\u30c8\u3092\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u66f8\u3044\u3066\u3057\u307e\u3046\u3068\u3001\u3069\u3053\u306b\u4f55\u304c\u3042\u308b\u304b\u304c\u5206\u304b\u308a\u306b\u304f\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u30eb\u30fc\u30c8\u3092\u5206\u5272\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u300c<strong>routes<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u3092\u3064\u304f\u308a\u3001\u305d\u306e\u4e2d\u306b\u300c<strong>users.js<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5524\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_22.png\" alt=\"\" width=\"258\" height=\"132\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u4e2d\u8eab\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>const express = require('express');\r\nconst router = express.Router();\r\n\r\nrouter.get('\/', (req, res) =&gt; {\r\n\r\n  res.send('\u300cusers\u300d\u306e\u4e00\u89a7\u30da\u30fc\u30b8');\r\n\r\n});\r\nrouter.get('\/:id', (req, res) =&gt; {\r\n\r\n  res.send('\u300cusers\u300d\u306e\u500b\u5225\u30da\u30fc\u30b8');\r\n\r\n});\r\n\r\nmodule.exports = router;<\/strong><\/pre>\n<p>\u7d9a\u3044\u3066\u3001\u300c<strong>app.js<\/strong>\u300d\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>\/\/ \u30eb\u30fc\u30c8\r\n<strong>app.use('\/users', require('.\/routes\/users'));<\/strong><\/pre>\n<p>\u3067\u306f\u3001<code>npm<\/code>\u3092\u518d\u8d77\u52d5\u3057\u3066\u30d6\u30e9\u30a6\u30b6\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5526\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_23.png\" alt=\"\" width=\"481\" height=\"82\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_23.png 481w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_23-300x51.png 300w\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5525\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_24.png\" alt=\"\" width=\"490\" height=\"82\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_24.png 490w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_24-300x50.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<p>\u3053\u306e\u65b9\u6cd5\u3092\u5fdc\u7528\u3059\u308c\u3070\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f7f\u3063\u3066\u3001<code>\/users<\/code>\u968e\u5c64\u306f\u8981\u30ed\u30b0\u30a4\u30f3\u306b\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b<code>:id<\/code>\u306e\u5024\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<pre>router.use(express.json());\r\nrouter.use(express.urlencoded({ extended: true }));\r\n\r\nrouter.get('\/<strong>:id<\/strong>', (req, res) =&gt; {\r\n  <strong>const userId = req.params.id;\r\n<\/strong>\r\n});<\/pre>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u65b0\u305f\u306a\u8a66\u307f\u3068\u3057\u3066<code>Node.js<\/code>\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af<code>Express<\/code>\u3092\u4f7f\u3063\u3066\u57fa\u672c\u7684\u306a\u5185\u5bb9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u521d\u3081\u3066\u672c\u683c\u7684\u306b<code>Express<\/code>\u3092\u4f7f\u3063\u3066\u307f\u305f\u96d1\u611f\u3067\u3059\u304c\u3001\u3084\u306f\u308a\u300c\u3044\u304b\u306b<code>Laravel<\/code>\u304c\u4fbf\u5229\u6a5f\u80fd\u3092\u305f\u304f\u3055\u3093\u6301\u3063\u3066\u3044\u308b\u304b\u300d\u3092\u5b9f\u611f\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u3044\u3046\u306e\u3082\u3001<code>Laravel<\/code>\u3060\u3068DB\u30c6\u30fc\u30d6\u30eb\u3092\u7ba1\u7406\u3059\u308b\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u304c\u6a19\u6e96\u642d\u8f09\u3057\u3066\u3044\u307e\u3059\u3057\u3001\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3082\uff08\u6700\u8fd1\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u3057\u3066\u5206\u96e2\u3055\u308c\u307e\u3057\u305f\u304c\uff09\u6700\u521d\u304b\u3089\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001DB\u30e2\u30c7\u30eb\uff08<code>Eloquent<\/code>\uff09\u306e\u3088\u3046\u306a\u3082\u306e\u304c<code>Express<\/code>\u306b\u306f\u306a\u3044\u306e\u3067\u3001\u3053\u308c\u3082\u81ea\u524d\u3067\u5b9f\u88c5\u3059\u308b\u304b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u3001\u3082\u3057\u304f\u306fSQL\u6587\u3092\u76f4\u306b\u66f8\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3068\u306a\u308b\u3068\u3001\u3084\u306f\u308a\u4fdd\u5b88\u7ba1\u7406\u3084\u958b\u767a\u30b9\u30d4\u30fc\u30c9\u3092\u8003\u3048\u308b\u3068<code>Laravel<\/code>\u306e\u65b9\u304c\u512a\u4f4d\u304b\u306a\u3068\u611f\u3058\u3066\u3044\u307e\u3059\u3002\uff08<code>Express<\/code>\u521d\u5fc3\u8005\u306a\u306e\u3067\u91cd\u8981\u306a\u90e8\u5206\u304c\u629c\u3051\u3066\u3044\u308b\u53ef\u80fd\u6027\u306f\u9ad8\u3044\u3067\u3059\u304c\u30fb\u30fb\u30fb\uff09<\/p>\n<p>\u307e\u305f\u3001<code>Node.js<\/code>\u306e\u4e00\u756a\u306e\u6b20\u70b9\u306f<strong>\u300c\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3068\u3001\u30b5\u30fc\u30d0\u30fc\u304c\u843d\u3061\u308b\u300d<\/strong>\u3002\u3053\u308c\u306b\u3064\u304d\u307e\u3059\ud83d\ude2b\uff08\u305f\u3060\u3057\u3001\u3053\u306e\u70b9\u306b\u95a2\u3057\u3066\u306f\u89e3\u6c7a\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308b\u305d\u3046\u306a\u306e\u3067\u3001\u4eca\u5f8c\u6398\u308a\u4e0b\u3052\u3066\u8abf\u67fb\u3057\u3066\u3044\u3053\u3046\u304b\u3068\u8003\u3048\u3066\u3044\u307e\u3059\uff09<\/p>\n<p>\u305f\u3060\u3001\u3084\u3063\u3071\u308a\u5b9f\u884c\u30b9\u30d4\u30fc\u30c9\u306e\u9ad8\u901f\u5316\u3068\u3044\u3046\u306e\u306f\u3068\u3066\u3082\u5927\u304d\u306a\u9b45\u529b\u306a\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u4f7f\u3063\u3066\u307f\u3088\u3046\u306a\u304b\u306a\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u3002<\/p>\n<p>\u7686\u3055\u3093\u3082\u305c\u3072<code>Express<\/code>\u306b\u30c1\u30a7\u30ec\u30f3\u30b8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-25 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15.png\" alt=\"\" width=\"348\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15.png 348w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15-300x276.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15-30x28.png 30w\" sizes=\"auto, (max-width: 348px) 100vw, 348px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u9045\u308c\u307e\u3057\u305f\u304c\u3001\u65b0\u5e74\u3042\u3051\u307e\u3057\u3066\u304a\u3081\u3067\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002<br \/>\n\u672c\u5e74\u3082\u300c<strong>Console dot Log<\/strong>\u300d\u3092\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3044\u305f\u3057\u307e\u3059\u3002m_ _m\u2728\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u307e\u3067\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306fLaravel\u3084Vue\u306e\u8a18\u4e8b\u3092\u591a\u304f\u516c\u958b\u3057\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u306e\u5ea6\u300c\u3088\u308a\u9ad8\u901f\u306b\u52d5\u304f\u30b5\u30a4\u30c8\u300d\u3092\u958b\u767a\u3059\u308b\u53ef\u80fd\u6027\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001\u3053\u308c\u307e\u3067\u864e\u8996 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=5485\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u5165\u9580\uff01Express\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u57fa\u672c\u306e\u307e\u3068\u3081&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":5527,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[201,203],"tags":[41,202],"class_list":["post-5485","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-express","category-node-js","tag-41","tag-202"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5485"}],"version-history":[{"count":15,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5485\/revisions"}],"predecessor-version":[{"id":5742,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5485\/revisions\/5742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/5527"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}