Minimalist server creation and management library
// ESModule
import { ServerShell } from "tsmservershell";
// RequireJS
const { ServerShell } = require("tsmservershell");
const app = new ServerShell();
app.listen();
You can use a specific configuration, using http.ServerOptions
as a basis :
const app = new ServerShell({
port: 3000,
});
app.listen();
Use the public methods to add routes going to a specific path of your application, and bind them to a function that will run for all incoming requests going to that route.
The req
parameter represents the Request object, and the res
parameter represents the Response object.
app.get("/get", (req, res) => {
// Route callback
});
app.post("/post", (req, res) => {
// Route callback
});
The middleware function will be called for every incoming requests
app.use((req, res) => {
// Middleware function
});
app.useStatic("./static/directory", "/route/root");
... or use dynamic reloading with useDynamic
:
app.useDynamic("./any/directory", "/route/root");