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 🙏

© 2026 – Pkg Stats / Ryan Hefner

chat-module

v1.3.0

Published

Independent chat module

Downloads

14

Readme

Chat-Module

Chat module is independent module for chatting, you have no need to save your messages anywhere, this module automatically done this.

install

	npm install chat-module

Events for chats

 * Below are the events that needs to understand for using this module - 	 
 		1. CHAT_USER_ONLINE - this event fire when any user reached online.
		2. CHAT_USER_OFFLINE - this event fire when any user reached offline.
		3. CHAT_NEW - this event is fire when a user wants to chat with new user that he haven't chat before.
		4. CHAT_NEW_MESSAGE - this event is fire whenever a new message sent.
		5. CHAT_NEW_PARTICIPANTS - this event is fire when a new participant added into group chat.
		6. CHAT_REMOVED_PARTICIPANTS - this event is fire when an existing user removed from group chat.
		7. CHAT_REMOVED_FROM - this event fire to user who removed from group chat.
		8. CHAT_LEFT - this event fire when user left chat by himself.

Set user id in request query while connecting socket from front-end, so it can set particular user socket.

	Ex.-

	io.connect('http://localhost:9980/chatroom', {
  query: 'user_id=' + userId
  });

Here "/chatroom" is the namespace for chat.

Setup chat

	* Create a folder name config in your root directory.
	* Create a file in config folder name default.json.
	* Set redisdb and mongodb configuration in json file as
			{
				"redis": {
						"server": "",
						"port": "",
						"options": {}
					},
					"mongo" : {
						 "uri": "",
						 "options": {}
					 }
			}

```js

var chat = require('chat');
chat.setup(server);

server : node server.

```

Initialize chat with namespace

	```js
	var chat = require('chat');
	var room = chat.init(namespace);

	```

	* Init method has one parameters.

	1. namespace: namespace for start chat.		

-----------------------------------------room instance have following functions-----------------------

Initiate private chat

	```js

	room.initiateChat(initiatorId,reciverId,callback);

	```
	* Method has three parameters.

	1. initiatorId: id of user who want to chat.
	2. reciverId: id of user to whom wants to chat.
	3. callback function.

Initiate group chat

```js

room.initiateGroupChat(initiatorId, participants, title, icon, callback);

```
* Method has four parameters.

1. initiatorId: id of user who creates group.
2. participants: array of user ids wants to added in group.
3. title: title for group.
4. icon: url for group image icon.(optional)
5. callback: callback function.

Post message on chat

	```js

	room.newMessage(chatId,fromUserId,browserId,message,callback);

	```
	* Method has four parameters.

	1. chatId : chat id (mongo id) in which user wants to chat either private or group chat.
	2. fromUserId : user id who send message.
	3. message : object
			ex. message = {
				text: 'hi this is new message', // required field
				file: 'url of shared file'      // optional field
			}
	4. browserId: unique id of browser.		
	5. callback function.

Add participants in group chat (any member in group can add new participant)

		```js

		room.addParticipants(chatId,userId,participants,callback)

		```
		* Method has four parameters.

		1. chatId : chat id (mongo id) in which user wants to add participants.
		2. userId :	user id who wants to add participants.
		3. participants : array of user ids.
		4. callback function.

Remove participants from group chat (only admin can remove participant from group)

		```js

		room.removeParticipants(chatId,userId,participants,callback)

		```
		* Method has four parameters.

		1. chatId : chat id (mongo id) in which user wants to remove participants.
		2. userId :	id of group admin.
		3. participants : array of user ids.
		4. callback function.

Get chat by id

		```js

		room.getChat(chatId,userId,callback);

		```
		* Method has three parameters.

		1. chatId : chat id (mongo id) user wants to get.
		2. userId : id of user.
		3. callback function.

Get chat messages

		```js

		room.getChatMessages(chatId,userId,skip,limit,callback);

		```
		* Method has three parameters.

		1. chatId : chat id (mongo id).
		2. userId : id of user.
		3. skip: skip.
		4. limit : limit.
		5. callback function.

Update chat

		```js

		room.updateChat(chatId,userId,title,icon,callback);

		```
		* Method has five parameters.

		1. chatId : chat id (mongo id).
		2. userId : id of user exist in group.
		3. title : title to be update //required
		4. icon : url of group icon image.
		5. callback function.

leave chat

		```js

		room.leaveChat(chatId, userId, callback);

		```
		* Method has three parameters.

		1. chatId : chat id (mongo id).
		2. userId : id of user who wants to leave chat.			
		5. callback function.

get chats

		```js

		room.getChats(userId, callback);

		```
		* Method has two parameters.

		2. userId : id of user who wants to get chats.			
		5. callback function.