[{"data":1,"prerenderedAt":797},["ShallowReactive",2],{"news-item-\u002Fja\u002Fnews\u002Fxay-dung-ung-dung-chat-realtime-voi-framework-meteor-js":3},{"id":4,"title":5,"body":6,"category":784,"created by":785,"date":786,"description":787,"extension":788,"meta":789,"navigation":790,"path":791,"sections":792,"seo":793,"stem":794,"thumbnail":795,"__hash__":796},"content_ja\u002Fja\u002Fnews\u002Fxay-dung-ung-dung-chat-realtime-voi-framework-meteor-js.md","Meteor.jsフレームワークを使ったRealtime Chatアプリのビルド",{"type":7,"value":8,"toc":772},"minimark",[9,16,20,23,29,32,38,44,50,56,62,68,74,81,88,93,96,107,122,128,131,137,142,157,163,166,174,181,187,197,201,205,209,215,243,249,269,275,282,288,294,298,301,306,312,318,328,334,339,345,355,358,364,370,388,398,404,410,419,425,432,438,441,447,453,459,465,468,479,483,488,492,498,507,513,519,525,528,532,535,545,551,559,565,572,578,584,590,595,601,606,612,619,625,628,632,635,639,645,650,654,658,671,674,686,689,701,704,716,719,731,734,737,742,748,751,754,760,766],[10,11,13],"h1",{"id":12},"紹介",[14,15,12],"strong",{},[17,18,19],"p",{},"Meteor（Meteor.js）は、Node.jsをベースにしたフルスタックJavaScriptフレームワークであり、Webおよびモバイルアプリケーションの迅速かつ効率的な開発を可能にします。クライアントとサーバー間のスムーズな統合を最適化した設計により、Meteorはコード共有プロセスを簡素化するだけでなく、リアルタイムデータのエクスペリエンスを向上させます。",[17,21,22],{},"もし、迅速なアプリケーション開発のソリューションを探している場合、または最新のWeb技術に関する知識を広げたい場合は、この記事がMeteorについての概要と深い洞察を提供します。",[10,24,26],{"id":25},"meteorの特徴",[14,27,28],{},"Meteorの特徴",[17,30,31],{},"このセクションでは、Meteorの際立った特徴をさらに詳しく探り、このフレームワークがWebおよびモバイル開発分野でどのように差別化され、ユニークであるかを見ていきます。",[17,33,34,37],{},[14,35,36],{},"クライアントとサーバーとのスムーズな統合","：Meteorは自動的なデータ同期モデルを提供し、複雑なデータ同期コードを書く必要なく、クライアントとサーバーの両方でデータをリアルタイムに更新することを可能にします。",[17,39,40,43],{},[14,41,42],{},"クライアントとサーバーとのコード共有","：Meteorを使用すると、コード共有が容易になり、アプリケーションの開発および保守プロセスを最適化できます。",[17,45,46,49],{},[14,47,48],{},"リアルタイムデータの更新","：MeteorはDDP（Distributed Data Protocol）を使用してクライアントとサーバーとのデータを同期化し、データを迅速かつスムーズに更新できるアプリケーションを実現します。",[17,51,52,55],{},[14,53,54],{},"強力なエコシステム","：Meteorは、MongoDBとの統合から、Meteor独自のホスティングサービスであるGalaxyを使用したアプリケーションのデプロイまで、数千のパッケージやツールを備えた豊富なエコシステムを提供します。",[17,57,58,61],{},[14,59,60],{},"ホットコードプッシュ機能","：この機能により、開発者はユーザー体験を妨げることなくアプリケーションを更新することができ、アプリの保守と更新において大きな利点を提供します。",[17,63,64,67],{},[14,65,66],{},"マルチプラットフォーム対応","：一度コードを書くことで、それをWebアプリとしてデプロイしたり、AndroidやiOS向けのモバイルアプリとしてビルドしたりすることができます。",[10,69,71],{"id":70},"meteorjsで開始",[14,72,73],{},"Meteor.jsで開始",[17,75,76,77,80],{},"Meteorを始めるには、Node.jsが既にインストールされていることを確認する必要があります。現在、MeteorはNode.jsの",[14,78,79],{},"バージョン10～14","をサポートしており、Meteor 3.0は、最新のNode.jsバージョンをサポートするために開発されています。",[82,83,85],"h2",{"id":84},"meteorインストール",[14,86,87],{},"Meteorインストール",[17,89,90],{},[14,91,92],{},"Windows、Linux、OS X",[17,94,95],{},"上記のプラットフォームにおいて、以下のコマンドをターミナルで実行することでMeteorをインストールできます。",[97,98,103],"pre",{"className":99,"code":101,"language":102},[100],"language-text","npm install -g meteor\n","text",[104,105,101],"code",{"__ignoreMap":106},"",[17,108,109,110,113,114,117,118,121],{},"また、",[14,111,112],{},"Linux","と",[14,115,116],{},"OS X","では、",[104,119,120],{},"curl","経由で以下のコマンドを使用してMeteorをインストールすることもできます。",[97,123,126],{"className":124,"code":125,"language":102},[100],"curl https:\u002F\u002Finstall.meteor.com\u002F | sh\n",[104,127,125],{"__ignoreMap":106},[82,129,130],{"id":130},"簡単なリアルタイムチャットアプリの作成",[17,132,133,136],{},[14,134,135],{},"Meteor.js","についてさらに学ぶために、以下のように、簡単なリアルタイムチャットプロジェクトを一緒に作成してみましょう！",[138,139,141],"h4",{"id":140},"_1-プロジェクトの初期化","1. プロジェクトの初期化",[17,143,144,145,148,149,152,153,156],{},"プロジェクトを迅速にセットアップするには、",[104,146,147],{},"meteor create","コマンドに",[104,150,151],{},"--blaze","オプションを付けて実行します。ここでは、プロジェクト名を「",[14,154,155],{},"simple-chat-meteor","」とします。",[97,158,161],{"className":159,"code":160,"language":102},[100],"meteor create --blaze simple-chat-meteor\n",[104,162,160],{"__ignoreMap":106},[17,164,165],{},"初期化が成功した後、ターミナルに次のようなメッセージが表示されます。",[167,168],"img",{"className":169,"alt":106,"src":172,"style":173},[170,171],"block","mx-auto","https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19133739\u002Fimg01-e1708324777843.png","width: 100%;",[17,175,176,177,180],{},"アプリケーションを実行するには、プロジェクトディレクトリへ辿って、",[104,178,179],{},"meteor run","コマンドを使用します。",[97,182,185],{"className":183,"code":184,"language":102},[100],"cd simple-chat-meteor\nmeteor run\n",[104,186,184],{"__ignoreMap":106},[17,188,189,190,196],{},"ブラウザを開き、",[191,192,193],"a",{"href":193,"rel":194},"http:\u002F\u002Flocalhost:3000",[195],"nofollow"," にアクセスすると、そのアプリケーションが見えます。",[167,198],{"className":199,"alt":106,"src":200,"style":173},[170,171],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19135639\u002Fimg02.png",[138,202,204],{"id":203},"_2-プロジェクト構成","2. プロジェクト構成",[167,206],{"className":207,"alt":106,"src":208,"style":173},[170,171],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F20092348\u002Fimg09.png",[17,210,211,214],{},[14,212,213],{},".meteor","：Meteorアプリケーションにおいて最も重要なディレクトリです。このディレクトリには、Meteorアプリケーションのコア設定ファイルと以下のようなサブディレクトリが含まれています。",[216,217,218,225,231,237],"ul",{},[219,220,221,224],"li",{},[14,222,223],{},"local","：アプリケーションのローカルデータやログファイルを格納する",[219,226,227,230],{},[14,228,229],{},"packages","：アプリケーションに使われているライブラリのリストを格納する",[219,232,233,236],{},[14,234,235],{},"platforms","：アプリケーションが対応しているプラットフォームを格納する",[219,238,239,242],{},[14,240,241],{},"versions","：アプリケーションに使われているライブラリのバージョン情報を保存するファイルです。",[17,244,245,248],{},[14,246,247],{},"client","：アプリケーションのクライアント側のソースコードを格納するディレクトリであり、以下のものが含まれます。",[216,250,251,257,263],{},[219,252,253,256],{},[14,254,255],{},"main.css","：クライアント側のスタイルを定義する主なCSSファイル",[219,258,259,262],{},[14,260,261],{},"main.html","：アプリケーションのレイアウトやテンプレートを定義する原点となる主なHTMLファイル",[219,264,265,268],{},[14,266,267],{},"main.js","：Blazeテンプレートのイベントやヘルパーを定義するところとなるクライアント用の主なJavaScriptファイル",[17,270,271,274],{},[14,272,273],{},"server","：アプリケーションのサーバー側ソースコードを格納するディレクトリであり、以下のものが含まれます。",[216,276,277],{},[219,278,279,281],{},[14,280,267],{},"：パブリケイションやメソッドの設定、およびサーバー初期化の設定を行うところとなるサーバー用の主なJavaScriptファイル",[17,283,284,287],{},[14,285,286],{},"tests","：アプリケーションのテストファイルを格納するディレクトリです。",[17,289,290,293],{},[14,291,292],{},"node_modules","：プロジェクトが依存しているNPMパッケージを格納するディレクトリです。",[138,295,297],{"id":296},"_3-各機能の実装","3. 各機能の実装",[17,299,300],{},"このセクションでは、Meteorチャットアプリケーションに機能を追加するために必要な手順を説明します。これには、ユーザーインターフェースの設定、イベント処理、ログインおよびログアウト機能の構築が含まれます。",[17,302,303],{},[14,304,305],{},"ユーザーインターフェースの設定",[17,307,308,311],{},[14,309,310],{},"client\u002Fmain.html","ファイルでは、チャットアプリの基本的なHTML構造を定義します。これには、タイトルやモバイルデバイスでの表示を最適化するためのmetaタグが含まれます。",[97,313,316],{"className":314,"code":315,"language":102},[100],"\u003Chead>\n  \u003Ctitle>Simple Chat Meteor\u003C\u002Ftitle>\n  \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \u002F>\n  \u003Cmeta charset=\"utf-8\"\u002F>\n  \u003Cmeta http-equiv=\"x-ua-compatible\" content=\"ie=edge\"\u002F>\n  \u003Cmeta\n      name=\"viewport\"\n      content=\"width=device-width, height=device-height, viewport-fit=cover, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no\"\n  \u002F>\n  \u003Cmeta name=\"mobile-web-app-capable\" content=\"yes\"\u002F>\n  \u003Cmeta name=\"apple-mobile-web-app-capable\" content=\"yes\"\u002F>\n\u003C\u002Fhead>\n",[104,317,315],{"__ignoreMap":106},[17,319,320,323,324,327],{},[14,321,322],{},"client\u002Fmain.js","ファイルでは、UIチャットを初期化するために",[14,325,326],{},"Chat.js","ファイルをインポートします。",[97,329,332],{"className":330,"code":331,"language":102},[100],"import '..\u002Fimports\u002Fui\u002FChat\u002FChat.js';\n\n",[104,333,331],{"__ignoreMap":106},[17,335,336],{},[14,337,338],{},"イベントとデータの処理",[17,340,341,344],{},[14,342,343],{},"imports","ディレクトリを作成して、UIとロジックの毎に分けられるソースコードを格納します。",[17,346,347,350,351,354],{},[14,348,349],{},"imports\u002Fui\u002FChat","内に、",[14,352,353],{},"Chat.html","ファイルを作成し、チャットアプリケーションのユーザーインターフェースを定義します。",[17,356,357],{},"Blazeテンプレートを使用して、中身と表示ロジックを整理します。",[97,359,362],{"className":360,"code":361,"language":102},[100],"\u003Cbody>\n    {{> chatContainer}}\n\u003C\u002Fbody>\n\n\u003Ctemplate name=\"chatContainer\">\n    \u003Cdiv class=\"chat-container\">\n        \u003Cdiv class=\"chat-header\">\n            \u003Ch2>Simple Chat Meteor\u003C\u002Fh2>\n        \u003C\u002Fdiv>\n\n        {{> chatContent}}\n    {{> chatInput}}\n    \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n\n\u003Ctemplate name=\"chatContent\">\n    \u003Cdiv class=\"chat-content\">\n        {{#each chats}}\n        \u003Cdiv class=\"message\">\n            \u003Cdiv class=\"username\">{{ username }}\u003C\u002Fdiv>\n            \u003Cdiv class=\"message-content\">{{ messageText }}\u003C\u002Fdiv>\n        \u003C\u002Fdiv>\n        {{\u002Feach}}\n    \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n\n\u003Ctemplate name=\"chatInput\">\n    \u003Cdiv class=\"chat-input\">\n        \u003Cinput id=\"message\" type=\"text\" placeholder=\"Input your message...\" \u002F>\n        \u003Cbutton id=\"sendMessage\">Send\u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[104,363,361],{"__ignoreMap":106},[17,365,366,369],{},[14,367,368],{},"chatContainer","：アプリケーションのヘッダー（chat-header）とチャット内容部分といったチャットアプリケーションのインターフェースの全部を含むメインテンプレートです。",[17,371,372,375,376,379,380,383,384,387],{},[14,373,374],{},"chatContent","：チャット内容を表示するためのより小さいなテンプレートであり、",[14,377,378],{},"chats","（各メッセージ）分、繰り返して、",[14,381,382],{},"username","（送信した者の名前）と",[14,385,386],{},"messageText","（メッセージ内容）を表示させます。",[17,389,390,393,394,397],{},[14,391,392],{},"chatInput","：ユーザーが新しいメッセージを送信できるようにするための他のテンプレートであり、メッセージ内容を入力するための入力項目と、メッセージを送信するための",[14,395,396],{},"Send","ボタンがあります。",[17,399,400,403],{},[14,401,402],{},"client\u002Fmain.css","ファイルに以下のCSSを追加します。",[97,405,408],{"className":406,"code":407,"language":102},[100],":root {\n  --main-bg-color: #f0f2f5;\n  --chat-bg-color: #fff;\n  --highlight-color: #f69914;\n  --text-color-white: #fff;\n  --border-color: #ddd;\n  --input-border-color: #ccc;\n  --hover-bg-color: #0056b3;\n}\n\nbody {\n  font-family: Arial, sans-serif;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  height: 100vh;\n  overflow: hidden;\n  margin: 0;\n  background-color: var(--main-bg-color);\n}\n\n.chat-container {\n  height: 100%;\n  width: 600px;\n  border: 1px solid var(--border-color);\n  background-color: var(--chat-bg-color);\n  display: flex;\n  flex-direction: column;\n}\n\n.chat-header {\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  background-color: var(--highlight-color);\n  color: var(--text-color-white);\n  height: 68px;\n  padding: 0px 10px;\n}\n\n.chat-header button#logout {\n  height: 30px;\n  background-color: transparent;\n  cursor: pointer;\n  color: var(--text-color-white);\n  border: 1px solid var(--chat-bg-color);\n  border-radius: 10px;\n}\n\n.chat-content {\n  padding: 10px;\n  height: calc(100vh - 90px - 57px);\n  overflow-y: auto;\n  gap: 10px;\n}\n\n.chat-content .message {\n  background-color: #f1f1f1;\n  padding: 10px;\n  border-radius: 10px;\n  display: flex;\n  flex-direction: column;\n}\n\n.chat-content .message:not(:first-child) {\n  margin-top: 10px;\n}\n\n.chat-content .message .username {\n  font-weight: bold;\n  color: var(--highlight-color);\n}\n\n.chat-content .message .message-content {\n  margin-top: 5px;\n}\n\n.chat-input {\n  display: flex;\n  padding: 10px;\n  height: 57px;\n  box-sizing: border-box;\n}\n\n.chat-input input {\n  flex: 1;\n  padding: 10px;\n  margin-right: 10px;\n  border: 1px solid var(--input-border-color);\n  border-radius: 4px;\n}\n\n.chat-input button {\n  padding: 10px;\n  background-color: var(--highlight-color);\n  color: white;\n  border: none;\n  border-radius: 4px;\n  cursor: pointer;\n}\n\n.chat-input button:hover {\n  background-color: var(--hover-bg-color);\n}\n\n.auth-container {\n  background-color: white;\n  padding: 40px;\n  border-radius: 5px;\n  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n  width: 300px;\n}\n\n.auth-container h2 {\n  text-align: center;\n  margin-bottom: 20px;\n}\n\n.auth-container p span {\n  text-decoration: underline;\n  color: var(--hover-bg-color);\n  cursor: pointer;\n}\n\n#loginForm .input-group,\n#signupForm .input-group {\n  margin-bottom: 15px;\n  display: flex;\n  flex-direction: column;\n}\n\n#loginForm .input-group label,\n#signupForm .input-group label {\n  margin-bottom: 5px;\n}\n\n#loginForm .input-group input,\n#signupForm .input-group input {\n  padding: 10px;\n  border: 1px solid var(--border-color);\n  border-radius: 4px;\n}\n\n#loginForm button,\n#signupForm button {\n  background-color: orange;\n  color: white;\n  padding: 10px;\n  border: none;\n  border-radius: 4px;\n  cursor: pointer;\n  width: 100%;\n}\n\n#loginForm button:hover,\n#signupForm button:hover {\n  background-color: darkorange;\n}\n",[104,409,407],{"__ignoreMap":106},[17,411,412,350,415,418],{},[14,413,414],{},"imports\u002Fapi",[14,416,417],{},"ChatsCollection.js","を作成します。",[97,420,423],{"className":421,"code":422,"language":102},[100],"import { Mongo } from 'meteor\u002Fmongo';\n\nexport const ChatsCollection = new Mongo.Collection('chats');\n",[104,424,422],{"__ignoreMap":106},[17,426,427,350,429,418],{},[14,428,414],{},[14,430,431],{},"ChatsPublications.js",[97,433,436],{"className":434,"code":435,"language":102},[100],"import { Meteor } from \"meteor\u002Fmeteor\";\n\nimport { ChatsCollection } from \".\u002FChatsCollection\";\n\nMeteor.publish(\"chats\", function () {\n  return ChatsCollection.find({}, { sort: { createdAt: -1 } });\n});\n",[104,437,435],{"__ignoreMap":106},[17,439,440],{},"次に、Meteorでチャットのデータベースに接続し、サーバーからチャットデータを登録して、ユーザーインターフェースでメッセージを時系列順に表示するようにします。",[17,442,443,446],{},[14,444,445],{},"imports\u002Fui\u002FChat\u002FChat.js","に以下のコードを追加します。",[97,448,451],{"className":449,"code":450,"language":102},[100],"import { Template } from \"meteor\u002Ftemplating\";\nimport { ChatsCollection } from \"\u002Fimports\u002Fapi\u002FChatsCollection\";\nimport \".\u002FChat.html\";\n\nMeteor.subscribe(\"chats\");\n\nTemplate.chatContent.helpers({\n  chats() {\n    return ChatsCollection.find({}, { sort: { createdAt: 1 } });\n  },\n});\n",[104,452,450],{"__ignoreMap":106},[17,454,455,458],{},[14,456,457],{},"server\u002Fmain.js","のコードを以下のように置き換えます。",[97,460,463],{"className":461,"code":462,"language":102},[100],"import { Meteor } from \"meteor\u002Fmeteor\";\nimport { ChatsCollection } from \"\u002Fimports\u002Fapi\u002FChatsCollection\";\nimport '\u002Fimports\u002Fapi\u002FChatsPublications';\n\nMeteor.startup(() => {\n  if (ChatsCollection.find().count() === 0) {\n    ChatsCollection.insert({\n      messageText: 'Welcome to the chat app!',\n      createdAt: new Date(),\n      username: \"Admin\",\n    });\n  }\n});\n",[104,464,462],{"__ignoreMap":106},[17,466,467],{},"目的としは、サーバー起動時にメッセージが存在しない場合、デフォルトのメッセージを追加することです。",[17,469,470,471,473,474,478],{},"→ ",[104,472,179],{},"コマンドを使用して、Meteor.js アプリケーションを起動します。その後、",[191,475,193],{"href":476,"rel":477},"http:\u002F\u002Flocalhost:1337\u002Farticle",[195],"にアクセスして結果を確認できます。",[167,480],{"className":481,"alt":106,"src":482,"style":173},[170,171],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19160033\u002Fimg04.png",[17,484,485],{},[14,486,487],{},"メッセージ送信機能の実装",[17,489,490,446],{},[14,491,445],{},[97,493,496],{"className":494,"code":495,"language":102},[100],"...\n\nTemplate.body.events({\n  \"click #sendMessage\": function () {\n    const messageElement = document.querySelector(\"#message\");\n    if (messageElement.value.trim()) {\n      Meteor.call(\"chats.sendMessage\", messageElement.value.trim());\n      messageElement.value = \"\";\n    }\n  },\n});\n",[104,497,495],{"__ignoreMap":106},[17,499,500,350,503,506],{},[14,501,502],{},"imports\u002Fap",[14,504,505],{},"ChatsMethods.js","を作成して、以下のコードを追加します。",[97,508,511],{"className":509,"code":510,"language":102},[100],"import { Meteor } from 'meteor\u002Fmeteor';\nimport { ChatsCollection } from \".\u002FChatsCollection\";\n\nMeteor.methods({\n    'chats.sendMessage'(message) {\n      ChatsCollection.insert({\n        messageText: message,\n        createdAt: new Date(),\n        username: \"Admin\"\n      });\n    }\n});\n",[104,512,510],{"__ignoreMap":106},[17,514,515,516,518],{},"次に、作成したてのメソッドを",[14,517,457],{},"ファイルにインポートします。",[97,520,523],{"className":521,"code":522,"language":102},[100],"...\nimport '\u002Fimports\u002Fapi\u002FChatsMethods';\n...\n",[104,524,522],{"__ignoreMap":106},[17,526,527],{},"ここで任意のメッセージを送信してみましょう！",[167,529],{"className":530,"alt":106,"src":531,"style":173},[170,171],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19161822\u002Fimg05.png",[17,533,534],{},"ログイン、登録、ログアウト機能の実装",[17,536,537,538,113,541,544],{},"以下のコマンドを使用して、",[14,539,540],{},"accounts-password",[14,542,543],{},"bcrypt","パッケージをインストールします",[97,546,549],{"className":547,"code":548,"language":102},[100],"meteor add accounts-password\nmeteor npm install --save bcrypt\n",[104,550,548],{"__ignoreMap":106},[17,552,553,350,556,506],{},[14,554,555],{},"imports\u002Fui\u002FAuth",[14,557,558],{},"Auth.html",[97,560,563],{"className":561,"code":562,"language":102},[100],"\u003Ctemplate name=\"authContainer\">\n    {{> Template.dynamic template=currentView}}\n\u003C\u002Ftemplate>\n\n\u003Ctemplate name=\"loginContainer\">\n    \u003Cdiv class=\"auth-container\" >\n        \u003Ch2>Login\u003C\u002Fh2>\n        \u003Cform id=\"loginForm\">\n            \u003Cdiv class=\"input-group\">\n                \u003Clabel for=\"username\">Username\u003C\u002Flabel>\n                \u003Cinput type=\"text\" id=\"username\" name=\"username\" required>\n            \u003C\u002Fdiv>\n            \u003Cdiv class=\"input-group\">\n                \u003Clabel for=\"password\">Password\u003C\u002Flabel>\n                \u003Cinput type=\"password\" id=\"password\" name=\"password\" required>\n            \u003C\u002Fdiv>\n            \u003Cbutton type=\"submit\">Login\u003C\u002Fbutton>\n        \u003C\u002Fform>\n\n        \u003Cp>Don’t have an account yet?\n            \u003Cspan>Sign up\u003C\u002Fspan>\n        \u003C\u002Fp>\n    \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n\n\u003Ctemplate name=\"signupContainer\">\n    \u003Cdiv class=\"auth-container\" >\n        \u003Ch2>Sign up\u003C\u002Fh2>\n        \u003Cform id=\"signupForm\">\n            \u003Cdiv class=\"input-group\">\n                \u003Clabel for=\"username\">Username\u003C\u002Flabel>\n                \u003Cinput type=\"text\" id=\"username\" name=\"username\" required>\n            \u003C\u002Fdiv>\n            \u003Cdiv class=\"input-group\">\n                \u003Clabel for=\"password\">Password\u003C\u002Flabel>\n                \u003Cinput type=\"password\" id=\"password\" name=\"password\" required>\n            \u003C\u002Fdiv>\n            \u003Cdiv class=\"input-group\">\n                \u003Clabel for=\"confirmPassword\">Confirm Password\u003C\u002Flabel>\n                \u003Cinput type=\"password\" id=\"rePassword\" name=\"confirmPassword\" required>\n            \u003C\u002Fdiv>\n            \u003Cbutton type=\"submit\">Sign up\u003C\u002Fbutton>\n        \u003C\u002Fform>\n\n        \u003Cp>Already have an account?\n            \u003Cspan>Login here\u003C\u002Fspan>\n        \u003C\u002Fp>\n    \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[104,564,562],{"__ignoreMap":106},[17,566,567,350,569,506],{},[14,568,555],{},[14,570,571],{},"Auth.js",[97,573,576],{"className":574,"code":575,"language":102},[100],"import { Template } from \"meteor\u002Ftemplating\";\nimport \".\u002FAuth.html\";\n\nimport { ReactiveVar } from \"meteor\u002Freactive-var\";\n\ncurrentView = new ReactiveVar(\"loginContainer\");\n\nTemplate.authContainer.helpers({\n  currentView: function () {\n    return currentView.get();\n  },\n});\n\nTemplate.loginContainer.events({\n  \"click span\": function (e) {\n    e.preventDefault();\n    currentView.set(\"signupContainer\");\n  },\n  \"submit #loginForm\"(e) {\n    e.preventDefault();\n\n    const target = e.target;\n\n    const username = target.username.value;\n    const password = target.password.value;\n\n    Meteor.loginWithPassword(username, password, (err) => {\n      if (err) {\n        alert(err);\n      }\n    });\n  },\n});\n\nTemplate.signupContainer.events({\n  \"click span\": function (e) {\n    e.preventDefault();\n    currentView.set(\"loginContainer\");\n  },\n  \"submit #signupForm\"(e) {\n    e.preventDefault();\n\n    const target = e.target;\n\n    const username = target.username.value;\n    const password = target.password.value;\n    const confirmPassword = target.confirmPassword.value;\n\n    if (password !== confirmPassword) {\n      alert(\"Password do not match\");\n      return;\n    }\n\n    Accounts.createUser(\n      {\n        username,\n        password,\n      },\n      (err) => {\n        if (err) {\n          alert(err);\n        }\n      }\n    );\n  },\n});\n",[104,577,575],{"__ignoreMap":106},[17,579,580,583],{},[14,581,582],{},"imports\u002Fui\u002FChat\u002FChat.html","で、ユーザーがログインしていることを確認し、ログアウトボタンを追加します。",[97,585,588],{"className":586,"code":587,"language":102},[100],"\u003Cbody>\n    {{#if isUserLogged}} {{> chatContainer}} {{else}} {{> authContainer}} {{\u002Fif}}\n\u003C\u002Fbody>\n\n...\n    \u003Cdiv class=\"chat-header\">\n        \u003Ch2>Simple Chat Meteor\u003C\u002Fh2>\n        \u003Cbutton id=\"logout\">Logout\u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n...\n",[104,589,587],{"__ignoreMap":106},[17,591,592,594],{},[14,593,445],{},"で、ユーザーがログインしていることを確認し、ログアウト処理を行います。",[97,596,599],{"className":597,"code":598,"language":102},[100],"import \"..\u002FAuth\u002FAuth.js\"\n...\nTemplate.body.helpers({\n  isUserLogged() {\n    return !!Meteor.userId() && !Meteor.loggingIn();\n  },\n});\n\nTemplate.body.events({\n  \"click #sendMessage\": function () {\n    const messageElement = document.querySelector(\"#message\");\n    if (messageElement.value.trim()) {\n      Meteor.call(\"chats.sendMessage\", messageElement.value.trim());\n      messageElement.value = \"\";\n    }\n  },\n  \"click #logout\": function () {\n    Meteor.logout();\n  },\n});\n",[104,600,598],{"__ignoreMap":106},[17,602,603,605],{},[14,604,457],{},"で、アカウント「admin」を確認して存在しなければ追加し、デフォルトメッセージに「username」を追加します。",[97,607,610],{"className":608,"code":609,"language":102},[100],"import { Meteor } from \"meteor\u002Fmeteor\";\nimport '\u002Fimports\u002Fapi\u002FChatsMethods';\nimport '\u002Fimports\u002Fapi\u002FChatsPublications';\nimport { ChatsCollection } from \"\u002Fimports\u002Fapi\u002FChatsCollection\";\nimport { Accounts } from 'meteor\u002Faccounts-base';\n\nconst SEED_USERNAME = \"admin\";\nconst SEED_PASSWORD = \"admin\";\n\nMeteor.startup(() => {\n  if (!Accounts.findUserByUsername(SEED_USERNAME)) {\n    Accounts.createUser({\n      username: SEED_USERNAME,\n      password: SEED_PASSWORD,\n    });\n  }\n\n  const user = Accounts.findUserByUsername(SEED_USERNAME);\n\n  if (ChatsCollection.find().count() === 0) {\n    ChatsCollection.insert({\n      messageText: 'Welcome to the chat app!',\n      createdAt: new Date(),\n      username: user.username,\n    });\n  }\n});\n",[104,611,609],{"__ignoreMap":106},[17,613,614,615,618],{},"同様に、",[14,616,617],{},"imports\u002Fapi\u002FChatsMethods.js","で「sendMessage」メソッドに「username」を追加します。",[97,620,623],{"className":621,"code":622,"language":102},[100],"import { Meteor } from 'meteor\u002Fmeteor';\nimport { ChatsCollection } from \".\u002FChatsCollection\";\n\nMeteor.methods({\n  'chats.sendMessage'(message) {\n    const username = Meteor.user()?.username;\n\n    ChatsCollection.insert({\n      messageText: message,\n      createdAt: new Date(),\n      username: username\n    });\n  }\n});\n",[104,624,622],{"__ignoreMap":106},[17,626,627],{},"成果物を見ましょう！！",[167,629],{"className":630,"alt":106,"src":631,"style":173},[170,171],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19172343\u002Fimg06.png",[17,633,634],{},"未ログイン状態でログイン画面が表示されます。",[167,636],{"className":637,"alt":106,"src":638,"style":173},[170,171],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19172346\u002Fimg07.png",[17,640,641],{},[642,643,644],"em",{},"サインアップ画面が出ます。",[167,646],{"className":647,"alt":106,"src":649,"style":173},[170,171,648],"mb-4","https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2024\u002F02\u002F19172349\u002Fimg08.png",[10,651,653],{"id":652},"expressjsと比較","Express.jsと比較",[655,656,657],"h3",{"id":657},"拡張性",[216,659,660,665],{},[219,661,662,664],{},[14,663,135],{},"は、開発を迅速かつ容易にするために、豊富な機能と事前に構築されたコンポーネントを備えた「開発ツールキット」を提供します。ただし、大規模なプロジェクトではカスタマイズや拡張性が制限される場合があります。",[219,666,667,670],{},[14,668,669],{},"Express.js","は、柔軟なフレームワークであり、開発者がアプリケーション構造を自由に設計できる環境を提供します。これにより、拡張性の高い大規模で複雑なプロジェクトに最適です。",[655,672,673],{"id":673},"リアルタイム通信",[216,675,676,681],{},[219,677,678,680],{},[14,679,135],{},"は、クライアントとサーバー間のリアルタイム通信機能を標準で備えており、ページをリロードせずにデータを即座に更新できます。",[219,682,683,685],{},[14,684,669],{},"は、同様の機能を実現するには、サードパーティライブラリを追加で統合する必要があり、開発工数が膨らみます。",[655,687,688],{"id":688},"データベース統合",[216,690,691,696],{},[219,692,693,695],{},[14,694,135],{},"は、MongoDBと密接に統合されており、その利用を最適化しています。そのためデータ管理が簡単になりますが、選択肢が制限される場合があります。",[219,697,698,700],{},[14,699,669],{},"は、SQLからNoSQLまで多様なデータベースとの接続をサポートしており、プロジェクトの要件に応じて柔軟に選択できます。",[655,702,703],{"id":703},"コミュニティとエコシステム",[216,705,706,711],{},[219,707,708,710],{},[14,709,135],{},"は、コミュニティは比較的小規模ですが、開発ニーズをサポートするための十分なパッケージやツールが提供されています。",[219,712,713,715],{},[14,714,669],{},"は、大規模で多様なコミュニティがあり、数千ものライブラリや追加ツールが存在します。これにより、アプリケーションの拡張や改善に多くの選択肢を提供します。",[655,717,718],{"id":718},"開発速度と習得難易度",[216,720,721,726],{},[219,722,723,725],{},[14,724,135],{},"は、多くの機能があらかじめ統合されているため、設定や管理作業を最小限に抑え、アプリケーション開発の速度を向上させます。学習曲線が比較的緩やかで、初心者に適しています。",[219,727,728,730],{},[14,729,669],{},"は、柔軟で高度にカスタマイズ可能なアプローチを提供しますが、設定に時間がかかる場合があります。それでも、長期的なプロジェクト開発では大きなメリットがあります。Node.jsの理解やミドルウェアの統合方法に関する知識が必要で、経験豊富な開発者に適しています。",[10,732,733],{"id":733},"結論",[17,735,736],{},"これまでの分析からして、Express.jsとMeteorはそれぞれ独自の長所と短所を持ち、異なる種類のプロジェクトや開発ニーズに適していることがわかります。",[17,738,739,741],{},[14,740,669],{},"は、高いカスタマイズ性と大規模な拡張性が必要なプロジェクトに適しています。特に、複雑で多様なデータベースや、大規模なエコシステムと豊富なライブラリやツールが求められるプロジェクトに最適です。",[17,743,744,745,747],{},"それに対して、",[14,746,135],{},"は、迅速かつ簡単な開発を求める場合に最適な選択肢です。特にリアルタイムアプリケーションや、MongoDBを必要とする小規模から中規模のプロジェクトに適しています。設定やインフラ管理に時間をかけず、アイデアの実現に集中したい開発者に向いています。",[17,749,750],{},"要約すると、Express.jsとMeteorの選択は、プロジェクトの具体的な要件、開発チームのスキルや経験、プロジェクトの目標やスケジュールに依存します。どちらの技術も独自の強みを持っており、適切な技術を選択することでプロジェクトの成功に大きく貢献します。",[10,752,753],{"id":753},"参照元",[17,755,756],{},[191,757,758],{"href":758,"rel":759},"https:\u002F\u002Fdocs.meteor.com\u002F",[195],[17,761,762],{},[191,763,764],{"href":764,"rel":765},"https:\u002F\u002Fwww.blazejs.org\u002F",[195],[17,767,768],{},[191,769,770],{"href":770,"rel":771},"https:\u002F\u002Fexpressjs.com\u002F",[195],{"title":106,"searchDepth":773,"depth":773,"links":774},2,[775,776],{"id":84,"depth":773,"text":87},{"id":130,"depth":773,"text":130,"children":777},[778,780,781,782,783],{"id":657,"depth":779,"text":657},3,{"id":673,"depth":779,"text":673},{"id":688,"depth":779,"text":688},{"id":703,"depth":779,"text":703},{"id":718,"depth":779,"text":718},"tech talk","HOANG PHAN THANH","2025-03-31","Meteor（Meteor.js）は、Node.jsをベースにしたフルスタックJavaScriptフレームワークであり、Webおよびモバイルアプリケーションの迅速かつ効率的な開発を可能にします。クライアントとサーバー間のスムーズな統合を最適化した設計により、Meteorはコード共有プロセスを簡素化するだけでなく、リアルタイムデータのエクスペリエンスを向上させます。もし、迅速なアプリケーション開発のソリューションを探している場合、または最新のWeb技術に関する知識を広げたい場合は、この記事がMeteorについての概要と深い洞察を提供します。","md",{},true,"\u002Fja\u002Fnews\u002Fxay-dung-ung-dung-chat-realtime-voi-framework-meteor-js",null,{"title":5,"description":787},"ja\u002Fnews\u002Fxay-dung-ung-dung-chat-realtime-voi-framework-meteor-js","https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2026\u002F06\u002F05080300\u002Fmeteor-logo-2.png","js2vcPBQiMKyLnQefzfU42rT_IkSInNJRVgLs01ctWc",1782263094638]