1.3.1 • Published 1 year ago

tsmservershell v1.3.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

TSM Server Shell

A TSM Studios production

Minimalist server creation and management library

Usage

Create a server from the ServerShell and start listening :

// 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();

Bind routes to the server :

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
});

Add middleware :

The middleware function will be called for every incoming requests

app.use((req, res) => {
  // Middleware function
});

Scan a directory for static assets :

app.useStatic("./static/directory", "/route/root");

... or use dynamic reloading with useDynamic :

app.useDynamic("./any/directory", "/route/root");
1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago