express-lazy-middleware
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

express-lazy-middleware

Linux Build Test Coverage Commitizen friendly NPM version NPM Downloads


Installation

$ npm install --save express-lazy-middleware
# Or with yarn
$ yarn add express-lazy-middleware

Usage

Basic usage:

'use strict';
/** Imports */
import * as Express from 'express';
import lazy from 'express-lazy-middleware';


/** Init */
app.get('/users', lazy(() => (req, res, next) => {
  res
    .send('I am too lazy');
}));


/** Start */
app.listen(3000);

Lazy require a module:

'use strict';
/** Imports */
import * as Express from 'express';
import lazy from 'express-lazy-middleware';


/** Init */
// `require` will be called after request to the `/users`.
// Note: when you use a ES6 module with `require()` don't forget about `default`
// export.
app.use('/users', lazy(() => require('./users').default));


/** Start */
app.listen(3000);

Init with promise:

'use strict';
/** Imports */
import * as Express from 'express';
import lazy from 'express-lazy-middleware';


/** Init */
// The `loader` (first argument) function will be called only once.
app.get('/session', lazy(async () => {
  await new Promise((resolve, reject) => {
    setTimeout(resolve, 5);
  });

  return require('./session').get;
}));


/** Start */
app.listen(3000);

Build

$ npm install
$ # or
$ yarn
$
$ npm run build

Test

$ npm run test

Contributing

  1. Fork it (https://github.com/SuperPaintman/express-lazy-middleware/fork)
  2. Create your feature branch (git checkout -b feature/<feature_name>)
  3. Commit your changes (git commit -am '<type>(<scope>): added some feature')
  4. Push to the branch (git push origin feature/<feature_name>)
  5. Create a new Pull Request

Contributors


Changelog

Changelog


License

MIT

Package Sidebar

Install

npm i express-lazy-middleware

Weekly Downloads

3

Version

0.1.0

License

MIT

Last publish

Collaborators

  • superpaintman