npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-io-chat

v1.0.7

Published

A package you can use to create a Chat with express and socket.io

Downloads

9

Readme

Chat Package

A package you can use to create a Chat with express and socket.io

Create a database

Create a file with this json content in it

{
  "users": {},
  "rooms": {}
}

Class Documentation

Setup

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const socketChat = require('socket.io-chat');
const Chat = new socketChat.Chat(app, {
  file: "./chat.json"
} // options that always will be the same, {
  messageCharacterLimit: 200, // Limit of characters of a message
  roomNameCharacterLimit: 30, // Limit of characters of a room name
  usernameCharacterLimit: 20, // Limit of characters of a username
} // options that can be defined and overwrited for each single request);

io.on('connection', (socket, name) => {});

Default options

Message Limit

Unlimited

Room Name Character Limit

Unlimited

Username Character Limit

Unlimited

Create Room

socket.on("createRoom", (options) => {
  const result = Chat.rooms({
    roomNameCharacterLimit: 50 // other options you can use to overwrite the options of the class
  }).create(socket.id, options, { roomNameCharacterLimit: 40 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Edit Room

socket.on("editRoom", (options) => {
  const result = Chat.rooms({
    roomNameCharacterLimit: 50 // other options you can use to overwrite the options of the class
  }).edit(socket.id, options, { roomNameCharacterLimit: 40 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Delete Room

socket.on("deleteRoom", (options) => {
  const result = Chat.rooms({
    // other options you can use to overwrite the options of the class, but there are currently no 
  }).delete(socket.id, options, { // this options can overwrite the other options, but there are currently no  });
  socket.emit(socket.id, result);
});

Get Room

socket.on("getRoom", (options) => {
  const result = Chat.rooms({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).get(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

All Rooms

socket.on("allRooms", (options) => {
  const result = Chat.rooms({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).all(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

Send Message

socket.on("sendMessage", (options) => {
  const result = Chat.messages({
    messageCharacterLimit: 20 // other options you can use to overwrite the options of the class
  }).send(socket.id, options, { messageCharacterLimit: 15 // this options can overwrite the other options });
  socket.emit(socket.id, result);
});

Edit Message

socket.on("editMessage", (options) => {
  const result = Chat.messages({
    messageCharacterLimit: 20 // other options you can use to overwrite the options of the class
  }).edit(socket.id, options, { messageCharacterLimit: 15 // this options can overwrite the other options });
  socket.emit(socket.id, result);
});

Delete Message

socket.on("deleteMessage", (options) => {
  const result = Chat.messages({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).delete(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

Get Message

socket.on("getMessage", (options) => {
  const result = Chat.messages({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).get(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

Create User

socket.on("createUser", (options) => {
  const result = Chat.users({
    usernameCharacterLimit: 15 // other options you can use to overwrite the options of the class
  }).create(socket.id, options, { usernameCharacterLimit: 25 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Edit User

socket.on("editUser", (options) => {
  const result = Chat.users({
    usernameCharacterLimit: 15 // other options you can use to overwrite the options of the class
  }).edit(socket.id, options, { usernameCharacterLimit: 25 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Delete User

socket.on("deleteUser", (options) => {
  const result = Chat.users({
    // other options you can use to overwrite the options of the class, but there are currently no 
  }).delete(socket.id, options, { // this options can overwrite the other options, but there are currently no  });
  socket.emit(socket.id, result);
});

Get User

socket.on("getUser", (options) => {
  const result = Chat.users({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).get(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

HTML Client Side Documentation

Setup

<script src="/socket.io-chat/socket.io-chat.js">

Configuration

const socket = io();
const chat new Chat(socket);

Create Room

Chat.rooms().create(options);

Edit Room

Chat.rooms().edit(options);

Delete Room

Chat.rooms().delete(options);

Get Room

Chat.rooms().get(options);

All Rooms

Chat.rooms().all();

Send Message

Chat.messages().send(options);

Edit Message

Chat.messages().edit(options);

Delete Message

Chat.messages().delete(options);

Get Message

Chat.messages().get(options);

Create User

Chat.users().create(options);

Edit User

Chat.users().edit(options);

Delete User

Chat.users().delete(options);

Get User

Chat.users().get(options);

Functions

[
  isURL,
  configRooms,
  createRoom,
  editRoom,
  deleteRoom,
  getRoom,
  allRooms,
  joinRoom,
  leaveRoom,
  sendMessage,
  editMessage,
  deleteMessage,
  getMessage,
  createUser,
  editUser,
  deleteUser,
  getUser,
  isURLSync,
  configRoomsSync,
  createRoomSync,
  editRoomSync,
  deleteRoomSync,
  getRoomSync,
  allRoomsSync,
  joinRoomSync,
  leaveRoomSync,
  sendMessageSync,
  editMessageSync,
  deleteMessageSync,
  getMessageSync,
  createUserSync,
  editUserSync,
  deleteUserSync,
  getUserSync
]

Classes

[
  Chat,
  RoomManager,
  MessageManager,
  UserManager,
  UtilManager,
  FunctionManager
]

Types

{
  "Types": {
    "Managers": {
      "Rooms": "rooms",
      "Messages": "messages",
      "Users": "users",
      "Util": "util",
      "Functions": "functions"
    }
  }
}