2.0.1 • Published 3 years ago
@reignmodule/express-utils v2.0.1
express services utilities
Common express services utilities
listeningListener()
listeningListener(this: ServerHttp): void
Use it to show a listener server.
Sample:
import { listeningListener } from '@reignmodule/express-utils/listening-listener';
createServerHttp(app).listen(3000, listeningListener);
// Server ready on http://localhost:3000
createServerHttps(app).listen(3001, listeningListener);
// Server ready on https://localhost:3001
createServerHttp2(app).listen(3002, listeningListener);
// Server ready on //localhost:3002
requestHandlerAsync
requestHandlerAsync(requestHandler: (req: Request, res: Response, next: NextFunction) => Promise<any>, thisArg?: any) => RequestHandler
Sample
import { requestHandlerAsync } from '@reignmodule/express-utils/handle-async';
const app = express();
app.get('/', requestHandlerAsync(async (req, res) => {
res.send('ok');
}));
errorRequestHandlerAsync
errorRequestHandlerAsync(errorRequestHandler: (error: any, req: Request, res: Response, next: NextFunction) => Promise<any>, thisArg?: any) => ErrorRequestHandler
Sample
import { errorRequestHandlerAsync } from '@reignmodule/express-utils/handle-async';
const app = express();
app.get('/', errorRequestHandlerAsync(async (err, req, res) => {
res.status(500).send(err.message);
}));
## requestParamHandlerAsync
requestParamHandlerAsync(requestParamHandler: (req: Request, res: Response, next: NextFunction, value: any, name: string) => Promise<any>, thisArg?: any) => RequestParamHandler
Sample
import { requestParamHandlerAsync } from '@reignmodule/express-utils/handle-async';
const app = express();
app.param('user', requestParamHandlerAsync(async (req, res, next, id, param) => {
const user = await User.find(id);
req.user = user;
return next();
}));
2.0.1
3 years ago
2.0.1-beta.1
3 years ago
2.0.1-beta.0
3 years ago
2.0.0-alpha.3
4 years ago
2.0.0-alpha.4
4 years ago
2.0.0-alpha.5
4 years ago
2.0.0-alpha.2
4 years ago
2.0.0
4 years ago
2.0.0-alpha.1
4 years ago
1.1.0-alpha.5
4 years ago
1.1.0-alpha.6
4 years ago
1.1.0-alpha.4
4 years ago
1.1.0-alpha.3
4 years ago
1.1.0-alpha.2
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago
1.0.0-beta.2
4 years ago
1.0.0-beta.1
4 years ago
1.0.0-beta.0
4 years ago