A simple and opinionated web server powered by Express.
This documentation is a work in progress.
npm i @guilhermemj/micro-web-server
var WebServer = require("@guilhermemj/micro-web-server");
var HTTP_PORT = 3000;
var webServer = new WebServer({
httpPort: HTTP_PORT,
routes: [
{
method: "get",
path: "/",
controller: (req, res) => {
res.send("Hi there!");
},
},
],
});
webServer.start().then(function () {
console.log("Web server started at port " + HTTP_PORT);
});
import WebServer, { Request, Response } from "@guilhermemj/micro-web-server";
const HTTP_PORT = 3000;
const webServer = new WebServer({
httpPort: HTTP_PORT,
routes: [
{
method: "get",
path: "/",
controller: (req: Request, res: Response) => {
res.send("Hi there!");
},
},
],
});
(async () => {
await webServer.start();
console.log(`Web server started at port ${HTTP_PORT}`);
})();
WebServer
constructor accepts an object with the following properties:
- Type:
number
. - Default:
3000
.
The HTTP port that the server will listen to.
- Type:
BodyParserOptions
. - Default:
undefined
.
Options object passed to express.json.
- Type:
CorsOptions
. - Default:
undefined
.
Options object passed to cors.
- Type:
Route[]
. - Default:
[]
.
Your application route definitions. Details will be described below.
- Type:
Controller
. - Default:
undefined
.
Middleware that should run before each route controller. It's usually used for logging purposes.