<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: admirableyetti</title>
    <description>The latest articles on DEV Community by admirableyetti (@admirableyetti).</description>
    <link>https://dev.to/admirableyetti</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F750648%2F73c4121a-45e1-4246-828e-bd313ec75245.png</url>
      <title>DEV Community: admirableyetti</title>
      <link>https://dev.to/admirableyetti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/admirableyetti"/>
    <language>en</language>
    <item>
      <title>Beginners socket.io code without cors error XD</title>
      <dc:creator>admirableyetti</dc:creator>
      <pubDate>Thu, 11 Nov 2021 16:54:51 +0000</pubDate>
      <link>https://dev.to/admirableyetti/beginners-socketio-code-without-cors-error-xd-2n83</link>
      <guid>https://dev.to/admirableyetti/beginners-socketio-code-without-cors-error-xd-2n83</guid>
      <description>&lt;p&gt;extensions required: live server that's all.&lt;/p&gt;

&lt;p&gt;I am going to assume that you already have previous programming knowledge and that you have tried to use socket.io and for any reason it has not worked for you, so I will share you the code that I used to make my first socket and that it worked especially for the problem of cors.&lt;/p&gt;

&lt;p&gt;to our blank project create the following files&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pY22c-oQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ob8kt82wrr2b7vhatoxq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pY22c-oQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ob8kt82wrr2b7vhatoxq.png" alt="files to create our first websocket" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;launch a new project with &lt;code&gt;npm init -y&lt;/code&gt; command it creates a file package.json then run &lt;code&gt;npm i nodemon socket.io&lt;/code&gt; and add line 9 on your package.json file that will use nodemon with server.js&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iPPDNEPZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7lldadq4legucza7z6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iPPDNEPZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7lldadq4legucza7z6z.png" alt="package.json file" width="603" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;add the following code to server.js file, usually live server use 5500 port,line 4 is where you give permission to connect...&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jb4Un4CY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhqviiflphgchx267qon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jb4Un4CY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhqviiflphgchx267qon.png" alt="server.js file" width="501" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;else it'll deny you access  and will throw cors error&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XDft1qGr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a32oel8gjzhzxw49aa1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XDft1qGr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a32oel8gjzhzxw49aa1.png" alt="cors error" width="880" height="31"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;index.js&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TnTOz4e6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gf17hroln5dbj8sr2ao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TnTOz4e6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gf17hroln5dbj8sr2ao.png" alt="index.js file" width="425" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;html file&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xMjZROFM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dxauaa3vo9vwi8o1095.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xMjZROFM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dxauaa3vo9vwi8o1095.png" alt="html file" width="710" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;once you have all we seen run &lt;code&gt;npm run serve&lt;/code&gt; and console will show init server, then on html file open live server open console and will show...&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---ymBVnkp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tt701o5elmfmf3cqclj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---ymBVnkp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tt701o5elmfmf3cqclj.png" alt="console will show init server" width="880" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now that it works you have the basic to begin on websockets, finally you have to search more and better info to make upgrade your code&lt;/p&gt;

&lt;p&gt;feel free to feedback&lt;/p&gt;

&lt;p&gt;and there you go, my first basic beginners socket.io post&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>websockets</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
