Gathering detailed insights and metrics for express-pack
Gathering detailed insights and metrics for express-pack
Gathering detailed insights and metrics for express-pack
Gathering detailed insights and metrics for express-pack
npm install express-pack
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
express-pack
simplifies Express.js app creation by bundling common middleware and providing a straightforward configuration system. Perfect for new projects or rapid prototyping!
dotenv
winston
helmet
body-parser
Install the package using npm or yarn:
npm install express-pack
yarn add express-pack
After installation, when you run the setup, you will be prompted with configuration questions.
1Do you want to use nodemon for development? (yes/no) 2 3- **Yes** → Adds a dev script using nodemon. 4- **No** → Uses node directly. 5
1Do you want to set up the basic Express app structure? (yes/no) 2 3- **Yes** → Automatically creates a structured Express.js app with controllers, routes, and configuration files. 4- **No** → Skips the setup and allows manual configuration. 5
If you choose to set up the Express app, the following directory structure will be created:
1/project-root 2 ├── /src 3 │ ├── /featureName1 4 │ │ ├── /controllers 5 │ │ ├── /routes 6 │ │ 7 │ ├── /featureName2 8 │ │ ├── /controllers 9 │ │ ├── /routes 10 ├── /config 11 │ ├── appConfig.js 12 │ └── routeConfig.js 13 ├── index.js 14 ├── package.json 15 └── .env
After setup, you can start the application using:
1npm run dev # If nodemon is enabled 2npm start # Runs the app with node
✅ Automatic project structure generation
✅ Support for nodemon for development
✅ Follows MVC architecture for clean code organization
✅ Quick setup with interactive prompts
express-pack
:1const { CreateApp, BindRoutes } = require("express-pack"); 2 3// routes arrays 4const { routes } = require("./config/routeConfig"); 5 6// app config for express-pack 7const { appConfig } = require("./config/appConfig"); 8 9// create app from express-pack 10const app = CreateApp(appConfig); 11 12// binding the routes with app 13BindRoutes(routes); 14 15app?.listen(3000, () => { 16 console.log("I am listening to 3000 port"); 17});
appConfig
object.✅ Easily create a new Express app
✅ Automatically apply a pre-configured with standard default settings
✅ Set up essential middleware for CORS, logging, body parsing, and security
1module.exports = { 2 appConfig: { 3 env: "development", // custom path for .env file 4 cors: {}, // CORS settings 5 logger: {}, // Logger configuration 6 bodyParser: {}, // Body parser settings 7 security: {}, // Security configurations 8 }, 9};
Handles request body parsing.
Option | Default Value | Description |
---|---|---|
json | { limit: "100kb" } | Limits JSON body size |
urlencoded | { extended: true, limit: "100kb" } | Parses URL-encoded bodies |
raw | { type: "application/octet-stream", limit: "100kb" } | Parses raw binary data |
text | { type: "text/plain", limit: "100kb" } | Parses plain text |
Example Usage:
1bodyParser: { 2 json: { limit: "1mb" }, 3 urlencoded: { extended: true, limit: "500kb" }, 4},
Manages cross-origin resource sharing.
Option | Default Value | Description |
---|---|---|
methods | ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"] | Allowed HTTP methods |
allowedHeaders | undefined | Headers allowed from requests |
exposedHeaders | [] | Custom headers exposed to client |
credentials | false | Allows sending cookies |
maxAge | 86400 | Cache preflight requests |
preflightContinue | false | Pass preflight responses to handlers |
Example Usage:
1cors: { 2 methods: ["GET", "POST"], 3 credentials: true, 4},
Handles application logging using Winston.
Option | Default Value | Description |
---|---|---|
level | "info" | Logging level |
format | timestamp + message | Log format |
transports | [Console, File] | Output destinations |
exitOnError | false | Exit on error |
Example Usage:
1logger: { 2 level: "debug", 3 transports: [new transports.Console()], 4},
Enhances security with Helmet.js settings.
Option | Default Value | Description |
---|---|---|
contentSecurityPolicy | false | Enables CSP headers |
dnsPrefetchControl | true | Controls DNS prefetching |
frameguard | "sameorigin" | Prevents clickjacking |
hsts | { maxAge: 0 } | HTTP Strict Transport Security |
noSniff | false | Prevents MIME sniffing |
xssFilter | true | Enables XSS protection |
Example Usage:
1security: { 2 hsts: { maxAge: 31536000 }, 3 xssFilter: false, 4},
Optimizes server performance by compressing HTTP responses.
Option | Default Value | Description |
---|---|---|
level | 6 | Compression level (0-9) for Gzip. Higher values result in better compression. |
threshold | 1024 | Only compress responses larger than 1KB. Smaller responses are sent uncompressed. |
filter | Function | A function to determine whether to apply compression based on request/response. |
Example Usage:
1compression: { 2 level: 9, 3 threshold: 2048, 4 filter: (req, res) => { 5 if (req.headers["x-no-compression"]) { 6 return false; // Skip compression if client requests no compression 7 } 8 return compression.filter(req, res); // Default compression filter 9 }, 10},
routes
array.1const TestRoute = require("../src/test/route"); 2 3module.exports = { 4 routes: [ 5 { 6 path: "/route", // Define the URL path for this route 7 route: TestRoute, // Link to the corresponding route file 8 }, 9 ], 10};
Router
.1const { Router } = require("express-pack"); 2const TestController = require("../controller/index"); 3 4// Define a GET endpoint for health checks or basic operations 5Router.get("/health-check", TestController.testMethod); 6 7// Define a POST endpoint for creating or processing data 8Router.post("/submit-data", TestController.testPostMethod); 9 10module.exports = Router;
CreateApp(config)
Creates an Express application pre-configured with essential middleware.
config
(Object) – Your application configuration.BindRoutes(routes)
Binds an array of routes to the application.
Parameters:
routes
(Array) – A list of route configurations.
Example:
1const routes = [{ path: "/api", route: ApiRoute }]; 2BindRoutes(routes);
1my-project/ 2├── config/ 3│ ├── appConfig.js # Application configuration 4│ └── routeConfig.js # Routes configuration 5├── src/ 6│ └── test/ # Your route handlers 7│ └── route.js # Example route handler 8├── index.js # Main entry point of the application 9 10
Special thanks to the developers and contributors who make Express.js development easier every day!
No vulnerabilities found.
No security vulnerabilities found.