Sockets - Beta

Wertik-js uses ws for websockets integration, Please see To see how Sockets is enabled please see This file enables Websockets with Wertik-js.

By default the socket server runs at port ws://localhost:2000. You can detect events for connected, message received and client disconnected by:

let object = {
  // Rest of the configuration
  sockets: {
  disable: false,
  port: 2000,
  onClientConnected: function(req, wss) {
      console.log("on client connected", `Total connections right now ${wss.clients.size}`);
    onMessageReceived: function(message) {
      console.log("on message received: " + message);
    onClientDisconnect: function(wss) {
      console.log("on client disconnected", `Total connections right now ${wss.clients.size}`);

Sending a message in Rest API handler

Consider this handler in your rest api handler, Websockets comes with, So you can send data,

async function(req, res) {"Test Message"); // This will send test message to all clients

In GraphQL, WebSockets can be accessed by,

function (_, args, context,info) {"Test Message"); // Tis will send test message to all clients from GraphQL

Currently Web Sockets in wertik-js are in beta, So more features are coming.