Installation - potatoscript/websocket GitHub Wiki

⚙️ Installation

Before we start using WebSockets, we need to set up our system properly! Follow these step-by-step instructions carefully. 🎯


🖥 Step 1: Install Node.js

💡 What is Node.js?
Node.js is like a magic toolbox 🛠️ that helps us create WebSocket servers.

📌 How to Install Node.js

1️⃣ Go to the official Node.js website: https://nodejs.org/
2️⃣ Download the "LTS" version (this is the stable version).
3️⃣ Install it by following the on-screen instructions.
4️⃣ Check if it’s installed:

  • Open Command Prompt (Windows) or Terminal (Mac/Linux).
  • Type this command:
    node -v
    
  • If you see a version number (e.g., v18.16.0), it’s installed! ✅

📂 Step 2: Create a New Project Folder

Now, we need a folder for our WebSocket project.

1️⃣ Open Command Prompt (Windows) or Terminal (Mac/Linux).
2️⃣ Type the following commands to create a folder:

mkdir websocket-demo
cd websocket-demo

3️⃣ This folder will store all our WebSocket files.


📜 Step 3: Initialize a Node.js Project

💡 What does this do?
This command creates a package.json file, which is like a shopping list 📜 for our project.

1️⃣ Inside your websocket-demo folder, run:

npm init -y

2️⃣ This will create a file called package.json.


📦 Step 4: Install the WebSocket Library

💡 Why do we need this?
The ws library helps us create WebSocket servers easily.

1️⃣ Run this command:

npm install ws

2️⃣ This will download and install the WebSocket library into your project.
3️⃣ Once done, you’ll see a new folder called node_modules (this stores all the installed tools).


🔥 Step 5: Verify Everything is Working

💡 Before we start coding, let’s check if everything is installed correctly!

1️⃣ Run this command:

node

2️⃣ This will open the Node.js interactive mode. You’ll see something like this:

Welcome to Node.js
>

3️⃣ Type this:

console.log("✅ Node.js is working!");

4️⃣ If it prints:

✅ Node.js is working!

Then everything is ready! 🎉


home

Websockets Reference Doc

  • Install node.js
  • Install live server in the VS Code
  • Create a project
    • server folder
      • index.js
      • run npm init -y and npm i ws --save
      • and it will create the following folder and files for you
        • node_modules
        • package.json
        • package-lock.json
    • client folder
      • index.html
      • script.js