{"id":1618,"date":"2021-12-29T22:15:06","date_gmt":"2021-12-29T13:15:06","guid":{"rendered":"https:\/\/dalomo.net\/blog\/?p=1618"},"modified":"2021-12-29T22:53:36","modified_gmt":"2021-12-29T13:53:36","slug":"%e7%b0%a1%e6%98%93%e6%8e%b2%e7%a4%ba%e6%9d%bf%e3%82%92%e4%bd%9c%e3%82%8a%e3%81%9f%e3%81%84%e3%80%81node-jsexpress%e3%81%a7-%e2%91%a1-nodebbs","status":"publish","type":"post","link":"https:\/\/dalomo.net\/blog\/2021\/12\/29\/1618\/","title":{"rendered":"\u7c21\u6613\u63b2\u793a\u677f\u3092\u4f5c\u308a\u305f\u3044\u3001node.js+express\u3067 \u2461\/nodebbs\u306b\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u3092\u4f5c\u308b"},"content":{"rendered":"<h1>\u6700\u521d\u306e\u30da\u30fc\u30b8<\/h1>\n<p>\u3068\u308a\u3042\u3048\u305aexpress\u3067\u30b5\u30fc\u30d0\u30fc\u3092\u7acb\u3066\u3066\u6700\u521d\u306eHTML\u3092\u8fd4\u305b\u308b\u3088\u3046\u306b\u306a\u308d\u3046\u3002<\/p>\n<h2>\u6e96\u5099<\/h2>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u308a\u30fc\u306e<\/p>\n<pre>$ mkdir \/home\/dalomo\/nodebbs<\/pre>\n<p>npm init\u3057\u30fc\u306e<\/p>\n<pre>$ npm init<\/pre>\n<p>express\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u30fc\u306e<\/p>\n<pre>$ npm install express --save<\/pre>\n<h2>express\u306eHello, world<\/h2>\n<p><a href=\"https:\/\/expressjs.com\/ja\/starter\/hello-world.html\">https:\/\/expressjs.com\/ja\/starter\/hello-world.html<\/a><\/p>\n<p>\u3053\u3061\u3089\u53c2\u8003\u306b<\/p>\n<pre><code class=\"js\">const express = require('express')\r\nconst app = express()\r\nconst port = 8850\r\n\r\napp.get('\/nodebbs', (req, res) =&gt; {\r\n  res.send('Hello World!')\r\n})\r\n\r\napp.listen(port, () =&gt; {\r\n  console.log(`Example app listening at http:\/\/localhost:${port}`)\r\n})<\/code><\/pre>\n<p>\u3053\u308c\u3067<\/p>\n<p>https:\/\/dalomo.net\/nodebbs\/<\/p>\n<p>\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068Hello, world\u3068\u3044\u3046\u6587\u5b57\u5217\u304c\u8fd4\u308b\u3002<\/p>\n<h2>\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3059\u3088\u3046\u306b\u3059\u308b<\/h2>\n<p>\u3093\u3067\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u7f6e\u304d\u5834\u3092\u4f5c\u308a\u30fc\u306e<\/p>\n<pre>$ mkdir \/home\/dalomo\/nodebbs\/public<\/pre>\n<p>\u3053\u306e\u4e2d\u306bindex.html\u3092\u7f6e\u3044\u3066\u304a\u304f\u3002<\/p>\n<pre><code class=\"js\">  res.send('Hello World!')<\/code><\/pre>\n<p>\u3092<\/p>\n<pre>res.sendFile(__dirname + '\/public\/index.html')\r\n<\/pre>\n<p>\u306b\u66f8\u304d\u63db\u3048\u3002\u305d\u3046\u3059\u308b\u3068<\/p>\n<p>https:\/\/dalomo.net\/nodebbs\/<\/p>\n<p>\u306b\u884c\u304f\u3068index.html\u304c\u8868\u793a\u3055\u308c\u308b\u3002\u307e\u3041\u3053\u308c\u3067\u3082\u3044\u3044\u3093\u3060\u3051\u3069\u3001\u3076\u3063\u3061\u3083\u3051\/nodebbs\u3067\u3084\u3063\u3066\u308b\u3053\u3068\u3063\u3066\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3057\u3066\u308b\u3060\u3051\u3060\u3002\u305d\u3046\u3044\u3046\u5834\u5408<\/p>\n<pre><code class=\"js\">app.get('\/nodebbs', (req, res) =&gt; {\r\n  res.sendFile('index.html')\r\n})<\/code><\/pre>\n<p>\u3092\u6d88\u3057\u3066<\/p>\n<pre>app.use('\/nodebbs', express.static('public'));<\/pre>\n<p>\u3067\u3088\u3044\u307f\u305f\u3044\u3002<\/p>\n<p><a href=\"https:\/\/expressjs.com\/ja\/starter\/static-files.html\">https:\/\/expressjs.com\/ja\/starter\/static-files.html<\/a><\/p>\n<h2>index.html\u306e\u4e2d\u8eab<\/h2>\n<p>\u3068\u308a\u307e\u30d5\u30a9\u30fc\u30e0\u3055\u3048\u3042\u308c\u3070\u3048\u3048\u3084\u308d\u3068\u3044\u3046\u4e8b\u3067<\/p>\n<div>\n<pre>  \u00a0 &lt;form action=\"\" method=\"POST\"&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;li&gt;\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;label for=\"name\"&gt;\u540d\u524d:&lt;\/label&gt;\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;input type=\"text\" id=\"name\" name=\"user_name\"&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;\/li&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;li&gt;\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;label for=\"msg\"&gt;\u5185\u5bb9:&lt;\/label&gt;\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;textarea id=\"msg\" name=\"user_message\"&gt;&lt;\/textarea&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;\/li&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;li class=\"button\"&gt;\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;button type=\"submit\"&gt;\u9001\u4fe1&lt;\/button&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;\/li&gt;\r\n  \u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\r\n\u00a0 \u00a0 &lt;\/form&gt;<\/pre>\n<\/div>\n<p>\u3068\u3057\u305f\u3002\u2193\u3092\u65e5\u672c\u8a9e\u306b\u3057\u305f\u3060\u3051<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Learn\/Forms\/Your_first_form\">https:\/\/developer.mozilla.org\/ja\/docs\/Learn\/Forms\/Your_first_form<\/a><\/p>\n<p>\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u3068\u304d\u306b\u3001action\u306e\u5185\u5bb9\u304c\u5b9f\u884c\u3055\u308c\u308b\u3002\u30d5\u30a9\u30fc\u30e0\u306e\u5185\u5bb9\u306fPOST\u30e1\u30bd\u30c3\u30c9\u3067\u52dd\u624b\u306b\u98db\u3076\u306e\u3067action\u306e\u5185\u5bb9\u3092\u4f5c\u3063\u3066\u3084\u308c\u3070\u3044\u3044\u3093\u3060\u306a\u3068\u601d\u3046\u3002\u305d\u3057\u305f\u3089\u6b21\u306f\u305d\u306e\u51e6\u7406\u3092\u4f5c\u3063\u3066\u3053\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u521d\u306e\u30da\u30fc\u30b8 \u3068\u308a\u3042\u3048\u305aexpress\u3067\u30b5\u30fc\u30d0\u30fc\u3092\u7acb\u3066\u3066\u6700\u521d\u306eHTML\u3092\u8fd4\u305b\u308b\u3088\u3046\u306b\u306a\u308d\u3046\u3002 \u6e96\u5099 \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4f5c\u308a\u30fc\u306e $ mkdir \/home\/dalomo\/nodebbs npm init\u3057\u30fc\u306e $ npm in &hellip; <a href=\"https:\/\/dalomo.net\/blog\/2021\/12\/29\/1618\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[132,130,157],"class_list":["post-1618","post","type-post","status-publish","format-standard","hentry","category-8","tag-express","tag-node-js","tag-157"],"_links":{"self":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/comments?post=1618"}],"version-history":[{"count":3,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1618\/revisions"}],"predecessor-version":[{"id":1622,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1618\/revisions\/1622"}],"wp:attachment":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/media?parent=1618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/categories?post=1618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/tags?post=1618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}