@knfs-tech/bamimi-socket.io
v1.0.7
Published
Simplify socket usage
Downloads
53
Readme
This package was developed to make using sockets easier because:
- Using router-like implementation in Express makes it easy for you to develop
- Can write functions as functions or divide into Controllers / Services
Install
npm i @knfs-tech/bamimi-socket.io
#or
yarn add @knfs-tech/bamimi-socket.io
Usage
Step 1: Create file config.js
module.exports = {
cors: {
origin: "*",
transports: ['websocket', 'polling'],
},
transports: ['websocket', 'polling'],
...
};
Note: You can see more information at socket.io
Step 2: Create file index.js
const { createServer } = require('node:http');
const config = require("/path/to/your-config")
const socket = require("@knfs-tech/bamimi-socket.io")
const express = require("express");
const app = express();
const server = createServer(app);
socket.io(server, config)
const connection = (io, socket) => {
console.log("____Connection___")
}
socket.on(
'/abc',
function (socket, next) {
console.log("___Middleware 1 socket___")
next()
},
function (socket, next) {
console.log("___Middleware 2 socket___")
next()
},
function (socket, next) {
console.log("___Middleware 3 socket___-")
next()
},
connection
)
server.listen(3001, () => {
console.log(`server running at http://localhost:3001`);
})
Step 3: Run file index.js
npm start
#or
node index.js
#or
yarn start
Author
Owner
License
Bamimi is open-sourced software licensed under the MIT license.