{"id":3818,"date":"2019-03-14T09:58:05","date_gmt":"2019-03-14T09:58:05","guid":{"rendered":"http:\/\/www.nsquareit.com\/blog\/?p=3818"},"modified":"2019-03-14T09:58:05","modified_gmt":"2019-03-14T09:58:05","slug":"node-chat-node-js-socket-io-chatroom","status":"publish","type":"post","link":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/","title":{"rendered":"Node Chat \u2013 Node js With Socket.io Chatroom."},"content":{"rendered":"<div class=\"entry-header\">\n<h1 class=\"entry-title\">Node Chat \u2013 Node js Socket.io Chatroom Free.<\/h1>\n<\/div>\n<div class=\"entry-content\">\n<article>\n<h4>In this tutorial, we are going to build a realtime chat system with\u00a0<a href=\"https:\/\/nodejs.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Node.js<\/a>\u00a0and the\u00a0<a href=\"http:\/\/socket.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">socket.io<\/a>\u00a0library.<\/h4>\n<h3 id=\"c5fd\"><strong>How do you create a simple chat application?<\/strong><\/h3>\n<h4>In this tutorial, I\u2019m going to help you create your own chat application. You can\u00a0 integrate\u00a0 into any project! This tutorial help to the complete development of a chat application.<\/h4>\n<h4>We\u2019re going to be creating a\u00a0<a href=\"https:\/\/nodejs.org\/en\/\">Node.js<\/a>\u00a0app, Please make sure you have it installed.<\/h4>\n<h4>Let\u2019s start :<\/h4>\n<ul>\n<li>create a folder<\/li>\n<li>cd into that directory in your terminal (command line)<\/li>\n<li>run\u00a0<code>npm init<\/code>\u00a0. This will create a new\u00a0<code>package.json<\/code>\u00a0file. (it will ask you name\/version, etc.)<\/li>\n<li><\/li>\n<\/ul>\n<h3>Node.js as a Web Server<\/h3>\n<p>The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client.<\/p>\n<p>Use the\u00a0<code>createServer()<\/code>\u00a0method to create an HTTP server:<\/p>\n<pre class=\"wp-block-preformatted\">var\u00a0http = require('http');\r\n\/\/create a server object:\r\nhttp.createServer(function\u00a0(req, res) {\r\n\u00a0 res.write('Hello World!');\u00a0\/\/write a response to the client\r\n\u00a0 res.end();\u00a0\/\/end the response\r\n}).listen(8080);\u00a0\/\/the server object listens on port 8080\r\n\r\n<\/pre>\n<h2>Getting started with rs-chat plugin<\/h2>\n<h4>You can install it through npm.<\/h4>\n<pre class=\"wp-block-preformatted\"><strong>\u00a0npm\u00a0install\u00a0rs-chat<\/strong><\/pre>\n<h3><\/h3>\n<h3>Setup for nodejs<\/h3>\n<h4>Open index.js or server.js or main.js file and put the below code and start nodejs server<\/h4>\n<pre class=\"wp-block-preformatted\"><strong>var\u00a0app\u00a0=\u00a0require('http')\r\nvar\u00a0chat\u00a0=\u00a0require('chat')\r\n\r\nchat.init({\r\n\u00a0\u00a0host\u00a0\u00a0\u00a0\u00a0\u00a0:\u00a0'localhost',\u00a0<\/strong><em><strong>\/\/\u00a0DB\u00a0host<\/strong><\/em><strong>\r\n\u00a0\u00a0user\u00a0\u00a0\u00a0\u00a0\u00a0:\u00a0'user',\u00a0<\/strong><em><strong>\/\/\u00a0DB\u00a0User<\/strong><\/em><strong>\r\n\u00a0\u00a0password\u00a0:\u00a0'password',\u00a0<\/strong><em><strong>\/\/\u00a0DB\u00a0Password<\/strong><\/em><strong>\r\n\u00a0\u00a0database\u00a0:\u00a0'database'\u00a0<\/strong><em><strong>\/\/\u00a0DB\u00a0Name<\/strong><\/em><strong>\r\n});<\/strong><\/pre>\n<h3>Create table<\/h3>\n<pre class=\"wp-block-preformatted\"><strong>CREATE\u00a0TABLE\u00a0`messages`\u00a0(\u00a0\r\n  `id`\u00a0int(11)\u00a0NOT\u00a0NULL,\r\n\u00a0`userId`\u00a0int(11)\u00a0NOT\u00a0NULL,\r\n\u00a0\u00a0`toId`\u00a0int(11)\u00a0NOT\u00a0NULL,\r\n\u00a0\u00a0`msg`\u00a0text\u00a0NOT\u00a0NULL,\r\n\u00a0\u00a0`created_at`\u00a0datetime\u00a0NOT\u00a0NULL\u00a0DEFAULT\u00a0CURRENT_TIMESTAMP,\r\n\u00a0\u00a0`read_at`\u00a0datetime\u00a0DEFAULT\u00a0NULL\r\n)\u00a0ENGINE=InnoDB\u00a0DEFAULT\u00a0CHARSET=latin1;<\/strong>\r\n\r\n<\/pre>\n<h3>Load the required files<\/h3>\n<h4>Inside the page\u2019s head tag include the CSS file.<\/h4>\n<pre class=\"wp-block-preformatted\"><strong>&lt;<\/strong>link\u00a0rel<strong>=<\/strong>\"stylesheet\"\u00a0type<strong>=<\/strong>\"text\/css\"\u00a0href<strong>=<\/strong>\"https:\/\/unpkg.com\/rs-chat@1.0.7\/dist\/rs-chat.min.css\"<strong>&gt;<\/strong><\/pre>\n<h4>In the page\u2019s footer, just before &lt;\/body&gt;, include the required JavaScript files.<\/h4>\n<pre class=\"wp-block-preformatted\"><strong>&lt;<\/strong>script\u00a0type<strong>=<\/strong>\"text\/javascript\"\u00a0src<strong>=<\/strong>\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/socket.io\/2.2.0\/socket.io.js\"<strong>&gt;&lt;\/<\/strong>script<strong>&gt;<\/strong>\r\n\r\n\r\n<strong>&lt;<\/strong>script\u00a0type<strong>=<\/strong>\"text\/javascript\"\u00a0href<strong>=<\/strong>\"https:\/\/unpkg.com\/rs-chat@1.0.7\/dist\/rs-chat.min.js\"<strong>&gt;&lt;\/<\/strong>script<strong>&gt;<\/strong>\r\n\r\n<\/pre>\n<h3>Instantiate the chat plugin<\/h3>\n<pre class=\"wp-block-preformatted\"><strong>&lt;script\u00a0type=\"text\/javascript\"&gt;\u00a0\r\n\u00a0RSChat.init({\r\n\u00a0socketUrl:\u00a0'http:\/\/localhost:8080\/'\u00a0<\/strong><em><strong>\/\/\u00a0server\u00a0url,<\/strong><\/em><strong>\r\n\u00a0\u00a0\u00a0\u00a0userId:\u00a0'1',\u00a0<\/strong><em><strong>\/\/\u00a0logged\u00a0in\u00a0user\u00a0id<\/strong><\/em><strong>\r\n\u00a0\u00a0\u00a0\u00a0name:\u00a0'ravi\u00a0shukla',\u00a0<\/strong><em><strong>\/\/\u00a0logged\u00a0in\u00a0user\u00a0name<\/strong><\/em><strong>\r\n\u00a0\u00a0});\r\n&lt;\/script&gt;<\/strong>\r\n\r\n<\/pre>\n<h4><strong>Call the below function to open chat box<\/strong><\/h4>\n<pre class=\"wp-block-preformatted\">RSChat.start('user_id',\u00a0'username')<\/pre>\n<h3>if you any error for installation nodejs chat plugin . Please go to git hub link\u00a0 and download.<\/h3>\n<\/article>\n<article>Website : <a href=\"https:\/\/www.tutsmake.com\">www.Tutsmake.com<\/a><\/article>\n<article>Npm Package :\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/rs-chat\">https:\/\/www.npmjs.com\/package\/rs-chat<\/a><br \/>\ngithub :\u00a0<a href=\"https:\/\/github.com\/ravishukla007\/chat\">https:\/\/github.com\/ravishukla007\/chat<\/a><br \/>\nYoutube :\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=TGWlZkFIuV8\">https:\/\/www.youtube.com\/watch?v=TGWlZkFIuV8<\/a><\/p>\n<blockquote class=\"wp-block-quote is-style-large\"><p>Support<\/p>\n<p>If you found a bug please submit it in the Issues.<\/p>\n<p>If you need help with implementing the chat in your project, You can mail me at\u00a0<a href=\"mailto:ravishkl5@gmail.com\">ravishkl5@gmail.com<\/a><\/p>\n<p>Suggestion<br \/>\nIf you have any suggestion, You can write mail to me at\u00a0<a href=\"mailto:ravishkl5@gmail.com\">ravishkl5@gmail.com<\/a><\/p>\n<p><cite><strong>This plugin powored by rs-chat\u00a0<\/strong><\/cite><\/p><\/blockquote>\n<\/article>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Node Chat \u2013 Node js Socket.io Chatroom Free. In this tutorial, we are going to build a realtime chat system with\u00a0Node.js\u00a0and the\u00a0socket.io\u00a0library. How do you create<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":3817,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[],"class_list":["post-3818","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-design-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Node Chat \u2013 Node js With Socket.io Chatroom. - NSquareIT<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node Chat \u2013 Node js With Socket.io Chatroom. - NSquareIT\" \/>\n<meta property=\"og:description\" content=\"Node Chat \u2013 Node js Socket.io Chatroom Free. In this tutorial, we are going to build a realtime chat system with\u00a0Node.js\u00a0and the\u00a0socket.io\u00a0library. How do you create [\u2026]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/\" \/>\n<meta property=\"og:site_name\" content=\"NSquareIT\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-14T09:58:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"627\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"NSquareIT\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"NSquareIT\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/\",\"url\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/\",\"name\":\"Node Chat \u2013 Node js With Socket.io Chatroom. - NSquareIT\",\"isPartOf\":{\"@id\":\"https:\/\/www.nsquareit.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png\",\"datePublished\":\"2019-03-14T09:58:05+00:00\",\"dateModified\":\"2019-03-14T09:58:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.nsquareit.com\/blog\/#\/schema\/person\/89a9a31d0938ea47d70306bdaca33a05\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#primaryimage\",\"url\":\"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png\",\"contentUrl\":\"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png\",\"width\":1200,\"height\":627},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.nsquareit.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Node Chat \u2013 Node js With Socket.io Chatroom.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.nsquareit.com\/blog\/#website\",\"url\":\"https:\/\/www.nsquareit.com\/blog\/\",\"name\":\"NSquareIT\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.nsquareit.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.nsquareit.com\/blog\/#\/schema\/person\/89a9a31d0938ea47d70306bdaca33a05\",\"name\":\"NSquareIT\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.nsquareit.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2aae590fac1e32352c6d1b917eddfd683ad5bd50d4f06fa2977d04850bd5032b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2aae590fac1e32352c6d1b917eddfd683ad5bd50d4f06fa2977d04850bd5032b?s=96&d=mm&r=g\",\"caption\":\"NSquareIT\"},\"url\":\"https:\/\/www.nsquareit.com\/blog\/author\/digitaladmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node Chat \u2013 Node js With Socket.io Chatroom. - NSquareIT","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/","og_locale":"en_US","og_type":"article","og_title":"Node Chat \u2013 Node js With Socket.io Chatroom. - NSquareIT","og_description":"Node Chat \u2013 Node js Socket.io Chatroom Free. In this tutorial, we are going to build a realtime chat system with\u00a0Node.js\u00a0and the\u00a0socket.io\u00a0library. How do you create [\u2026]","og_url":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/","og_site_name":"NSquareIT","article_published_time":"2019-03-14T09:58:05+00:00","og_image":[{"width":1200,"height":627,"url":"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png","type":"image\/png"}],"author":"NSquareIT","twitter_card":"summary_large_image","twitter_misc":{"Written by":"NSquareIT","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/","url":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/","name":"Node Chat \u2013 Node js With Socket.io Chatroom. - NSquareIT","isPartOf":{"@id":"https:\/\/www.nsquareit.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#primaryimage"},"image":{"@id":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png","datePublished":"2019-03-14T09:58:05+00:00","dateModified":"2019-03-14T09:58:05+00:00","author":{"@id":"https:\/\/www.nsquareit.com\/blog\/#\/schema\/person\/89a9a31d0938ea47d70306bdaca33a05"},"breadcrumb":{"@id":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#primaryimage","url":"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png","contentUrl":"https:\/\/www.nsquareit.com\/blog\/wp-content\/uploads\/2018\/12\/nodejs.png","width":1200,"height":627},{"@type":"BreadcrumbList","@id":"https:\/\/www.nsquareit.com\/blog\/node-chat-node-js-socket-io-chatroom\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.nsquareit.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Node Chat \u2013 Node js With Socket.io Chatroom."}]},{"@type":"WebSite","@id":"https:\/\/www.nsquareit.com\/blog\/#website","url":"https:\/\/www.nsquareit.com\/blog\/","name":"NSquareIT","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.nsquareit.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.nsquareit.com\/blog\/#\/schema\/person\/89a9a31d0938ea47d70306bdaca33a05","name":"NSquareIT","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.nsquareit.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2aae590fac1e32352c6d1b917eddfd683ad5bd50d4f06fa2977d04850bd5032b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2aae590fac1e32352c6d1b917eddfd683ad5bd50d4f06fa2977d04850bd5032b?s=96&d=mm&r=g","caption":"NSquareIT"},"url":"https:\/\/www.nsquareit.com\/blog\/author\/digitaladmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/posts\/3818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/comments?post=3818"}],"version-history":[{"count":1,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/posts\/3818\/revisions"}],"predecessor-version":[{"id":4030,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/posts\/3818\/revisions\/4030"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/media\/3817"}],"wp:attachment":[{"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/media?parent=3818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/categories?post=3818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsquareit.com\/blog\/wp-json\/wp\/v2\/tags?post=3818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}