Express server accelerator package. It uses the Service Registry pattern to create a single object with APIs.
- starts server on port 8000 by default
- request / response logging with tracing metadata
- asynchronous context within request flow
import { load } from '@101-ways/core-express';
load([`${__dirname}/modules`]).then((sr) => {
sr.express.app.get('/hello', (req, res) => {
res.json({ result: 'hello world' });
});
});
Basic example for creating a child package:
import { load as loadCore, type Registry } from '@101-ways/express';
export type { Registry };
export async function load<T extends Registry>(paths: string[] = [], sr?: T) {
return loadCore([`${__dirname}/modules`, ...paths], sr);
}
Everything in @101-ways/core and
- sr.config - configuration (see ./src/modules/config.ts)
- sr.express - Express module methods
- sr.express.app - Express app (see https://expressjs.com/en/4x/api.html#app)
- sr.express.returnError(req, res, err, code?) - helper function to log and return an error
- sr.express.server - HTTP server used by the app (see https://nodejs.org/api/http.html#class-httpserver)
Everything in @101-ways/core and
- PORT='8000' - HTTP server port