Getting started with "Hello world!" with socket messages.


Install node modules

npm install express
npm install

Node.js server

const express = require('express'); 
const app = express();
const server = app.listen(3000,console.log(" Hello Wolrd server started!"));
const io = require('')(server);

io.on('connection', (socket) => {
    //console.log("Client connected!");
    socket.on('message-from-client-to-server', (msg) => {
    socket.emit('message-from-server-to-client', 'Hello World!');

Browser client

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Hello World with</title>
    <script src=""></script>
      var socket = io("http://localhost:3000");
      socket.on("message-from-server-to-client", function(msg) {
          document.getElementById('message').innerHTML = msg;
      socket.emit('message-from-client-to-server', 'Hello World!');
    <p> Hello World client started!</p>
    <p id="message"></p>

In the above example, the path to the library is defined as /

Even though we didn't write any code to serve the library, automatically does that.