Socket
Socket
Sign inDemoInstall

express-lazy-router

Package Overview
Dependencies
63
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 1.0.5

3

lib/express-lazy-router.js

@@ -34,2 +34,5 @@ "use strict";

return resolver().then(function (router) {
if (!router) {
throw new Error("lazyLoad(resolver) the resolver function should return a promise object, but it returns falsy value: " + router + "\n\nYou need to return a promise object from the callback function.\n\n lazyLoad(() => import('./path_to_router')), \n");
}
if ("default" in router) {

@@ -36,0 +39,0 @@ loadedRouter = router.default;

@@ -28,2 +28,5 @@ import express from "express";

return resolver().then(function (router) {
if (!router) {
throw new Error("lazyLoad(resolver) the resolver function should return a promise object, but it returns falsy value: " + router + "\n\nYou need to return a promise object from the callback function.\n\n lazyLoad(() => import('./path_to_router')), \n");
}
if ("default" in router) {

@@ -30,0 +33,0 @@ loadedRouter = router.default;

4

package.json
{
"name": "express-lazy-router",
"version": "1.0.4",
"version": "1.0.5",
"description": "Lazy loading for express router",

@@ -37,3 +37,3 @@ "keywords": [

"clean": "rimraf lib/ module/",
"prepare": "git config --local core.hooksPath .githook",
"prepare": "git config --local core.hooksPath .githooks",
"prepublishOnly": "npm run clean && npm run build",

@@ -40,0 +40,0 @@ "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",

@@ -14,3 +14,3 @@ # express-lazy-router

In a frontend, We have already used lazy loading for router like React Router, Vue Router.
In a frontend, We have already used lazy loading with router like React Router, Vue Router.

@@ -22,4 +22,17 @@ - [Route-based code splitting | React](https://reactjs.org/docs/code-splitting.html#route-based-code-splitting)

So, We can get lazy routing in Node.js [Express routing](https://expressjs.com/en/guide/routing.html) too.
My motivation that We can do lazy routing in Node.js [Express routing](https://expressjs.com/en/guide/routing.html) too.
Results of my project:
> Use ts-node-dev + express
- Before:
- 123 ts file Compilation
- Total startup time: 34236ms
- After(use express-lazy-router):
- 14 ts file Compilation
- Total startup time: 14238ms
- Summary:
- Compilation time is 200ms per 1 ts file
## Install

@@ -134,7 +147,7 @@

- load `index.js`
- Compile `index.js` by babe;
- Compile `index.js` by babel or ts-node
- complete to launch the express app
- `GET /api/status`
- load `api.js`
- Compile `api.js` by babe;
- Compile `api.js` by babel or ts-node
- > `{ ok: true }`

@@ -152,5 +165,3 @@

const app = express();
app.use(
lazyLoad(() => import('./path_to_router')),
);
app.use(lazyLoad(() => import('./path_to_router')));
app.listen(port, () => {

@@ -157,0 +168,0 @@ console.log(`Example app listening at http://localhost:${port}`)

@@ -35,2 +35,10 @@ import express from "express";

return resolver().then((router) => {
if (!router) {
throw new Error(`lazyLoad(resolver) the resolver function should return a promise object, but it returns falsy value: ${router}
You need to return a promise object from the callback function.
lazyLoad(() => import('./path_to_router')),
`);
}
if ("default" in router) {

@@ -37,0 +45,0 @@ loadedRouter = router.default;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc