
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
async-server
Advanced tools
import { Server } from "async-server";
const app = new Server();
/index
and write out "Hello World"import { Server } from "async-server";
const app = new Server();
class IndexPage {
async GET(ctx) {
ctx.response = "Hello world";
}
}
// Register the route
app.route("/index", new IndexPage());
import { NodeServer } from "async-server";
const app = new Server();
class IndexPage {
async GET(ctx) {
ctx.response = "Hello world";
}
}
// Register the route
app.route("/index", new IndexPage());
// Port default to 8080, host default to localhost, backlog default to 0
await app.listen(80);
import { Server } from "async-server";
// Create the server
await new Server()
// Register the route
.route("/index", new class IndexPage {
async GET(ctx) {
ctx.response = "Hello world";
}
})
// Start the server
.listen(80);
To get query and body of a request use ctx.body
or ctx.query
To get the current url use ctx.url
To get the current request use ctx.request
.json
file.import { JsonDB } from "async-server";
// Create a database
const db = new JsonDB("Your json file path");
// Create a schema called user with `name` property typed `string` and `id` property typed `number`
const User = db.schema("User", {
name: String,
id: Number
});
// Create objects that matched the schema and save it to the database
let user = new User({
name: "Reve", // Matches type "String"
id: 863068 // Matches type "Number"
});
await user.save(); // Save to database
let user1 = new User({
name: "Alex", // Matches type "String"
id: 509390 // Matches type "Number"
});
await user1.save(); // Save to database
// Search for user with name equals `Alex` and object count set to 1 to returns only 1 object
await User.find({
name: "Alex"
}, 1).then(console.log);
// Clear all the objects belong to the schema that was created before
await User.clear();
// Clear the database
await db.clear();
FAQs
A lightweight framework
We found that async-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.