socket-metro
v1.0.1
Published
An Eventual socket-server without any affiliation (just by built-in modules)
Maintainers
Readme
Socket Metro
- use socket metro library for eventual process
Deps
Socket-Metro is using EventEmitter & net modules which they are built-in modules
Also Socket-Metro written in Typescript & NodeJS
Usage & Imports
download
npm install socket-metroimport
- nodejs
const { SocketMetro } = require("socket-metro");- tsc
import { SocketMetro } from "socket-metro";create server & configure it
let metro = new SocketMetro();
let metro = new SocketMetro({
host: "127.0.0.1", // or localhost & 0.0.0.0 -> default on 127.0.0.1
port: 4545, // random port -> default on 6567
polling: true, // start the server -> default is true
log: true // log information, its like verbose mode -> default is true
})use events
metro.on("receive", async (message) => {
console.log(message);
/*
param `message` has two keys which named
`event` and `data`. `event` is received event from client
that must be string, and `data` could be anything.
*/
})
metro.on("close", async (client) => {
console.log(client);
/*
param `client` has one key which named
`socket` that returns the Socket object of client that closed connection.
*/
})
metro.on("exception", async (except) => {
console.log(except);
/*
param `except` has 3 keys which named
`message` : string , `error` : Error, `socket` : net.Socket.
*/
})
