{"id":18181,"date":"2022-10-10T19:07:03","date_gmt":"2022-10-10T10:07:03","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=18181"},"modified":"2023-05-27T17:40:32","modified_gmt":"2023-05-27T08:40:32","slug":"%e3%80%90node-js%e3%80%91%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=18181","title":{"rendered":"\u3010Node.js\u3011\u57fa\u672c\u3001\u30e9\u30a4\u30d6\u30e9\u30ea"},"content":{"rendered":"<h2>Node.js\u3068\u306f\uff1f<\/h2>\n<p>\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306eJavaScript\u306e\u5b9f\u884c\u74b0\u5883\u306e\u3053\u3068\u3067\u3059\u3002\u975e\u540c\u671f\u578b\u306e\u30a4\u30d9\u30f3\u30c8\u99c6\u52d5\u30e2\u30c7\u30eb\u3092\u63a1\u7528\u3057\u3066\u3044\u307e\u3059\u3002Google\u304c\u958b\u767a\u3057\u305fChrome\u306b\u3082\u642d\u8f09\u3055\u308c\u3066\u3044\u308bJavaScript\u306e\u5b9f\u884c\u30a8\u30f3\u30b8\u30f3V8\u3092\u5229\u7528\u3057\u3066\u3001\u975e\u540c\u671f\u3067\u5927\u91cf\u306e\u30a2\u30af\u30bb\u30b9\u306b\u8010\u3048\u3046\u308bWeb\u30a2\u30d7\u30ea\u306e\u958b\u767a\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u6700\u8fd1\u3067\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u74b0\u5883\u3060\u3051\u3067\u306a\u304fwebpack\u3084Babel\u3001TypeScript\u30b3\u30f3\u30d1\u30a4\u30e9\u7b49\u306e<span style=\"color: #ff0000;\"><strong>Web\u958b\u767a\u3067\u4f7f\u7528\u3059\u308b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30c4\u30fc\u30eb\u3068\u3057\u3066\u306e\u5f79\u5272<\/strong><\/span>\u3067\u3082\u5e83\u304f\u4f7f\u308f\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u975e\u540c\u671f\u578b\u306e\u30a4\u30d9\u30f3\u30c8\u99c6\u52d5\u306eJavaScript\u30e9\u30f3\u30bf\u30a4\u30e0<\/h3>\n<p>libuv\u3068\u3044\u3046\u975e\u540c\u671fI\/O\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308bC\u8a00\u8a9e\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304b\u3089\u69cb\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Node.js\u306e\u52d5\u4f5c\u74b0\u5883<\/h2>\n<ul>\n<li>Mac<\/li>\n<li>Linux<\/li>\n<li>Windows<\/li>\n<\/ul>\n<h2>Node.js\u306e\u30e1\u30ea\u30c3\u30c8<\/h2>\n<h3>\u5927\u91cf\u306e\u30a2\u30af\u30bb\u30b9\u3092\u540c\u6642\u306b\u51e6\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u70b9<\/h3>\n<p>\u5f93\u6765\u306eWeb\u30a2\u30d7\u30ea\u3067\u306f\u3001\u3069\u3093\u306a\u306b\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u304c\u512a\u308c\u3066\u3044\u3066\u3082\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u9045\u5ef6\u7b49\u306b\u3088\u3063\u3066\u3001\u30a2\u30d7\u30ea\u306e\u52d5\u4f5c\u304c\u91cd\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<h3>\u5b66\u7fd2\u30b3\u30b9\u30c8\u304c\u4f4e\u3044\u70b9<\/h3>\n<p>JavaScript\u306e\u6587\u6cd5\u3067\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u958b\u767a\u7d4c\u9a13\u304c\u3042\u308c\u3070\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306e\u958b\u767a\u3082\u59cb\u3081\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3001\u5b66\u7fd2\u30b3\u30b9\u30c8\u304c\u4f4e\u3044\u3067\u3059\u3002<\/p>\n<h2>\u6628\u4eca\u3067\u306f\u3002<\/h2>\n<p>\u6628\u4eca\u8a71\u984c\u306b\u306a\u3063\u3066\u3044\u308b\u300cReact\u300d\u3084\u3001\u300cAngularJS\u300d\u7b49\u306e\u958b\u767a\u306b\u306fNode.js\u306f\u3001\u5fc5\u8981\u4e0d\u53ef\u6b20\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Node.js\u306e\u63a1\u7528\u4f8b<\/h2>\n<ul>\n<li>\u30b5\u30a4\u30d0\u30fc\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8<\/li>\n<li>Twitter<\/li>\n<li>PayPal<\/li>\n<li>Uber<\/li>\n<li>Netflix<\/li>\n<\/ul>\n<h2>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u9055\u3044\u3092\u610f\u8b58\u3059\u308b\u3053\u3068<\/h2>\n<p>Node.js\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u9055\u3044\u306e\u610f\u8b58\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n<h3>\u30b3\u30a2\u30e2\u30b8\u30e5\u30fc\u30eb<\/h3>\n<ul>\n<li>Node.js\u304c\u63d0\u4f9b\u3059\u308b\u30e2\u30b8\u30e5\u30fc\u30eb<\/li>\n<li>os\u3001fs\u3001path\u3001http<\/li>\n<\/ul>\n<h3>npm\u30e2\u30b8\u30e5\u30fc\u30eb<\/h3>\n<ul>\n<li>\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u88fd\u306e\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea<\/li>\n<li>express\u3001axios\u306a\u3069<\/li>\n<\/ul>\n<h3>\u30d5\u30a1\u30a4\u30eb\u30e2\u30b8\u30e5\u30fc\u30eb<\/h3>\n<ul>\n<li>\u81ea\u4f5c\u30e2\u30b8\u30e5\u30fc\u30eb<\/li>\n<\/ul>\n<h2>\u30e9\u30a4\u30d6\u30e9\u30ea<\/h2>\n<p>\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306eNode.js\u3067\u5b9f\u88c5\u3059\u308b\u969b\u306b\u3088\u304f\u4f7f\u308f\u308c\u3066\u3044\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u3044\u304f\u3064\u304b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>bcryptjs<\/h3>\n<h4>hash\u95a2\u6570<\/h4>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6697\u53f7\u5316\u304c\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const bcrypt = require(\"bcryptjs\");\r\nconst password = await bcrypt.hash(\"\u4efb\u610f\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\", 10);\r\n<\/pre>\n<h5>10<\/h5>\n<p>\u30bd\u30eb\u30c8\u3068\u547c\u3070\u308c\u308b\u3082\u306e\u3067\u524d\u5f8c\u306b\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u3064\u3051\u308b\u3068\u3044\u3046\u610f\u5473\u5408\u3044\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>compare\u95a2\u6570<\/h4>\n<pre class=\"lang:default decode:true\">const valid = await bcrypt.compare(\"\u30d5\u30ed\u30f3\u30c8\u304b\u3089\u6e21\u3055\u308c\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\", \"DB\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30d1\u30b9\u30ef\u30fc\u30c9\");<\/pre>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u5165\u529b\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3044\u307e\u3059\u3002\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u306a\u3069\u3067\u4f7f\u3048\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n<h4>\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/h4>\n<p>\u4f8b\u3048\u3070\u3001prisma\u306a\u3069\u3067\u65b0\u898f\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306a\u3069\u306bbcryptjs\u3067\u6697\u53f7\u5316\u3057\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u6e21\u3057\u3066\u3042\u3052\u307e\u3059\u3002<\/p>\n<h3>jsonwebtoken<\/h3>\n<p>\u7c21\u5358\u306bJWT\u3068\u3044\u3046\u30c8\u30fc\u30af\u30f3\u3092\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const jwt = require(\"jsonwebtoken\");\r\n<span class=\"pl-k\">const<\/span> <span class=\"pl-c1\">APP_SECRET<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s\">\"\u4efb\u610f\u306e\u79d8\u5bc6\u9375\u306e\u6587\u5b57\u5217\uff08\u306a\u3093\u3067\u3082\u826f\u3044\uff09\"<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\nconst token = jwt.sign({ userId: \"\u4efb\u610f\u306e\u30e6\u30fc\u30b6\u30fcID\" }, APP_SECRET);<\/pre>\n<h4>sign\u95a2\u6570<\/h4>\n<p>\u7f72\u540d\u3092\u3057\u3066\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u751f\u6210\u3059\u308b\u95a2\u6570\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>verify\u95a2\u6570<\/h4>\n<p>\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u9006\u306b\u6697\u53f7\u5316\u3055\u308c\u3066\u3044\u306a\u3044\u6b63\u5e38\u306a\u6587\u5b57\u5217\u306b\u30c7\u30b3\u30fc\u30c9\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">jwt.verify(\"\u30c8\u30fc\u30af\u30f3\", \"\u4efb\u610f\u306e\u79d8\u5bc6\u9375\");<\/pre>\n<h4>APP_SECRET<\/h4>\n<p>\u7f72\u540d\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u30b5\u30fc\u30d0\u30fc\u5074\u3060\u3051\u304c\u6301\u3063\u3066\u3044\u308b\u79d8\u5bc6\u9375\u3067\u3059\u3002\u7b2c\u4e09\u8005\u306e\u8ab0\u304b\u304c\u30c8\u30fc\u30af\u30f3\u3092\u62fe\u3063\u305f\u3068\u3057\u3066\u3082\u3053\u306e\u79d8\u5bc6\u9375\u304c\u306a\u3051\u308c\u3070\u30c7\u30b3\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u306e\u3067\u3088\u308a\u5b89\u5168\u306a\u5b9f\u88c5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/h4>\n<ul>\n<li>\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3067\u65b0\u898f\u3067\u30e6\u30fc\u30b6\u30fc\u4f5c\u6210\u5f8c\u3002<\/li>\n<li>\u30e6\u30fc\u30b6\u30fc\u30ed\u30b0\u30a4\u30f3\u6642<\/li>\n<\/ul>\n<p>\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u4f55\u304b\u8a8d\u8a3c\u304c\u3042\u308b\u305f\u3073\u306bsign\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3066\u30c8\u30fc\u30af\u30f3\u3092\u751f\u6210\u3057\u3066\u3044\u308b\u70b9\u3067\u3059\u3002\u30c8\u30fc\u30af\u30f3\u81ea\u4f53\u306fDB\u306b\u4fdd\u5b58\u3057\u305f\u308a\u3057\u3066\u6c38\u7d9a\u5316\u306f\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u30e6\u30fc\u30b6\u30fc\u306f\u4eca\u5f8c\u306f\u305d\u306e\u5272\u308a\u5f53\u3066\u308c\u3089\u305f\u30c8\u30fc\u30af\u30f3\u3092\u3082\u3068\u306b\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3068\u60c5\u5831\u3092\u3084\u308a\u53d6\u308a\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Node.js\u3068\u306f\uff1f \u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306eJavaScript\u306e\u5b9f\u884c\u74b0\u5883\u306e\u3053\u3068\u3067\u3059\u3002\u975e\u540c\u671f\u578b\u306e\u30a4\u30d9\u30f3\u30c8\u99c6\u52d5\u30e2\u30c7\u30eb\u3092\u63a1\u7528\u3057\u3066\u3044\u307e\u3059\u3002Google\u304c\u958b\u767a\u3057\u305fChrome\u306b\u3082\u642d\u8f09\u3055\u308c\u3066\u3044\u308bJavaScript\u306e\u5b9f\u884c\u30a8\u30f3\u30b8\u30f3V8\u3092\u5229 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[62],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18181"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18181"}],"version-history":[{"count":12,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18181\/revisions"}],"predecessor-version":[{"id":20057,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18181\/revisions\/20057"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18181"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}