A package that make online database with socket.io
npm install @evodev/neko.db-socketClient(config)
Client#connect()
Client#get(key, callback)
key's value and then call callback with key's value as argument. If callback is not a function, the code will return the value. This will throw an error if the client haven't connect to the server.
Client#on(event, callback)
id of the callback.
Client#once(event, callback)
Client#on but the callback can only be used once.
Client#off(id)
id.
Client#register()
Client#set(key, value, callback)
key's value into value. If callback is a function, the code will call calback with key's new value as argument. If callback is not a function, the code will return the new value. This will throw an error if the client haven't connect to the server.
Server(httpApp/port, config)
Server#on(event, callback)
id of the callback.
Server#once(event, callback)
Server#on but the callback can only be used once.
Server#off(id)
id.
js
let { Client } = require("../index.js");
let client = new Client({
url : "http://localhost:3000",
account: {
username: "Admin23",
password: "admin123"
}
});
client.on("connected", async () => {
console.log(Connected as ${client.connection.account.username}.);
let count = await client.get("count");
switch(count) {
case undefined:
count = 1;
await client.set("count", count);
break;
default:
count+=1;
await client.set("count", count);
break;
}
console.log(count);
client.on("disconnected", () => {
console.log(Disconnected.);
});
});
let connect = () => {
client.connect();
};
client.on("registered", connect);
client.on("alreadyRegistered", connect);
setTimeout(function() {
client.register();
}, 1000);
`
----
$3
----
`js
let { Server } = require("../index.js");
let http = require("http").createServer();
let server = new Server(http);
http.listen(3000, () => {
console.log("Listening at localhost:3000");
});
server.on("connection", (data) => {
console.log(A user is connected to the server.);
});
server.on("register", (data) => {
console.log(A user is registered it's account.);
});
server.on("registering", data => {
return { status: false, reason: "You dumb" };
});
server.on("connecting", data => {
return { status: false, reason: "You dumb" };
});
`
----
Note
> You can get all Client#on and Server#on events in test/note.txt.
---
Donation
> PayPal: nekomaru76`