express-genix 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Joshua Maeba Nyamasege
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,259 +1,209 @@
1
- # Express-Genix CLI
1
+ # Express-Genix
2
2
 
3
- express-genix is a production-grade CLI tool that generates Express.js applications with a robust, scalable foundation. It scaffolds projects with JWT authentication (including refresh tokens), MongoDB (with Mongoose) or PostgreSQL (with Sequelize), rate-limiting, security middleware (Helmet, CORS), custom logging, Swagger API documentation, Jest testing, ESLint (Airbnb style), Prettier formatting, and Docker support with database services.
4
-
5
- **NEW**: Now includes a "No Database" option for APIs that don't require database persistence - perfect for microservices, proxy servers, or computational APIs.
3
+ A production-grade CLI tool that generates Express.js applications with a robust, scalable foundation. Get a complete REST API up and running in seconds with authentication, database integration, security, testing, and Docker support.
6
4
 
7
5
  ## Features
8
6
 
9
- - Generates Express apps with a clean structure (src/server.js, src/app.js, src/routes, etc.)
10
- - **Three database options**: MongoDB (Mongoose), PostgreSQL (Sequelize), or No Database
11
- - Includes JWT-based authentication with register, login, refresh tokens, and logout (database modes)
12
- - Provides security (Helmet, CORS, rate-limiting), logging (Morgan, custom logger), and Swagger UI
13
- - Sets up Jest/Supertest for testing, ESLint for code quality, and Prettier for formatting
14
- - **Automatic post-generation cleanup** - runs `eslint --fix` and Prettier formatting
15
- - **Zero linting errors out of the box** - generated code is production-ready immediately
16
- - Docker configuration with database services for easy deployment
17
- - User-friendly CLI with input validation and detailed output
7
+ **🚀 Three Setup Options**
8
+ - **MongoDB** - Full-stack with Mongoose ORM and JWT authentication
9
+ - **PostgreSQL** - Enterprise-ready with Sequelize ORM and JWT authentication
10
+ - **No Database** - Perfect for microservices, proxy servers, or computational APIs
11
+
12
+ **🔐 Security & Authentication**
13
+ - JWT authentication with refresh tokens (database modes)
14
+ - Helmet security headers
15
+ - CORS configuration
16
+ - Rate limiting out of the box
17
+ - Password hashing with bcrypt
18
+
19
+ **📚 Developer Experience**
20
+ - Swagger/OpenAPI documentation
21
+ - Jest testing with Supertest
22
+ - ESLint (Airbnb) + Prettier pre-configured
23
+ - Auto-formatted code (zero linting errors)
24
+ - Structured logging
25
+ - Health check endpoints
26
+
27
+ **🐳 Production Ready**
28
+ - Docker & Docker Compose included
29
+ - Clustering support for performance
30
+ - Graceful shutdown handling
31
+ - Environment-based configuration
18
32
 
19
- ## Installation
33
+ ## Quick Start
20
34
 
21
- Install express-genix globally from npm to use it anywhere:
35
+ ### Installation
22
36
 
23
37
  ```bash
24
38
  npm install -g express-genix
25
39
  ```
26
40
 
27
- Alternatively, use it directly with npx without installation:
41
+ Or use directly with npx (no installation needed):
28
42
 
29
43
  ```bash
30
44
  npx express-genix init
31
45
  ```
32
46
 
33
- ## Usage
34
-
35
- Run the CLI to generate a new Express project:
47
+ ### Create Your Project
36
48
 
37
49
  ```bash
38
50
  express-genix init
39
51
  ```
40
52
 
41
- Or with npx:
53
+ Follow the prompts:
54
+ 1. **Project name** - Choose your project name (letters, numbers, hyphens, underscores)
55
+ 2. **Database** - Select MongoDB, PostgreSQL, or No Database
42
56
 
43
- ```bash
44
- npx express-genix init
45
- ```
57
+ The CLI will:
58
+ - Generate your project structure
59
+ - Install all dependencies
60
+ - Auto-format and lint the code
61
+ - Set up Docker configuration
46
62
 
47
- ### Prompts
48
-
49
- - **Project name**: Enter a name (letters, numbers, hyphens, underscores; default: my-express-app)
50
- - **Database**: Choose from:
51
- - **MongoDB (with Mongoose)** - Full authentication system with JWT
52
- - **PostgreSQL (with Sequelize)** - Full authentication system with JWT
53
- - **No Database (API without database)** - Example CRUD API with in-memory storage
54
-
55
- The CLI creates a project directory, generates files, installs dependencies, and **automatically formats and lints the code**.
56
-
57
- Navigate to the generated project (e.g., `cd my-express-app`) and run:
63
+ ### Run Your App
58
64
 
59
65
  ```bash
66
+ cd your-project-name
60
67
  npm run dev
61
68
  ```
62
69
 
63
- Visit `http://localhost:3000/api-docs` for Swagger documentation or `http://localhost:3000/health` for health checks.
70
+ Visit:
71
+ - **API Documentation**: http://localhost:3000/api-docs
72
+ - **Health Check**: http://localhost:3000/health
73
+
74
+ ## Generated API Endpoints
64
75
 
65
- ### Generated Project Features
76
+ ### With Database (MongoDB/PostgreSQL)
66
77
 
67
- **All Projects Include:**
68
- - Rate limiting, security middleware, logging
69
- - Swagger API documentation with OpenAPI 3.0
70
- - Jest testing with coverage
71
- - ESLint (Airbnb) + Prettier formatting
72
- - Docker support with clustering
73
- - Health checks and structured logging
78
+ **Authentication**
79
+ - `POST /api/auth/register` - Register new user
80
+ - `POST /api/auth/login` - User login
81
+ - `POST /api/auth/refresh` - Refresh access token
82
+ - `POST /api/auth/logout` - User logout
74
83
 
75
- **Database Projects Include:**
76
- - **Authentication**: `/api/auth/register`, `/api/auth/login`, `/api/auth/refresh`, `/api/auth/logout`
77
- - **User Management**: `/api/users/profile` (GET, PUT, DELETE)
78
- - **Features**: JWT with refresh tokens, password hashing (bcrypt)
84
+ **User Management** (Protected)
85
+ - `GET /api/users/profile` - Get user profile
86
+ - `PUT /api/users/profile` - Update user profile
87
+ - `DELETE /api/users/profile` - Delete user account
79
88
 
80
- **No-Database Projects Include:**
81
- - **Example API**: `/api/examples` (GET, POST, PUT, DELETE) with in-memory storage
82
- - **Perfect for**: Microservices, proxy servers, computational APIs
89
+ ### Without Database
83
90
 
84
- ### CLI Options
91
+ **Example API** (In-memory CRUD)
92
+ - `GET /api/examples` - List all examples (with pagination)
93
+ - `GET /api/examples/:id` - Get example by ID
94
+ - `POST /api/examples` - Create new example
95
+ - `PUT /api/examples/:id` - Update example
96
+ - `DELETE /api/examples/:id` - Delete example
97
+
98
+ ## Available Scripts
85
99
 
86
100
  ```bash
87
- express-genix init --skip-cleanup # Skip automatic formatting (for debugging)
101
+ npm run dev # Development server with hot reload
102
+ npm start # Production server with clustering
103
+ npm test # Run tests with coverage
104
+ npm run lint # Check code quality
105
+ npm run lint:fix # Auto-fix linting issues
106
+ npm run format # Format code with Prettier
107
+ npm run format:check # Verify code formatting
88
108
  ```
89
109
 
90
110
  ## Project Structure
91
111
 
92
- ### CLI Structure
93
- ```
94
- express-genix/
95
- ├── index.js # Main CLI entry point
96
- ├── package.json # CLI package configuration
97
- ├── README.md # This documentation
98
- ├── lib/
99
- │ ├── cleanup.js # Post-generation cleanup functions
100
- │ ├── generator.js # File generation logic
101
- │ └── utils.js # Utility functions
102
- └── templates/
103
- ├── core/ # Core files (app.js, server.js, etc.)
104
- ├── config/ # Configuration files
105
- ├── controllers/ # Route handlers
106
- ├── middleware/ # Custom middleware
107
- ├── models/ # Database models
108
- ├── routes/ # API routes
109
- ├── services/ # Business logic
110
- ├── utils/ # Utilities
111
- └── tests/ # Test files
112
- ```
113
-
114
- ### Generated Express App Structure
115
112
  ```
113
+ your-project/
116
114
  ├── src/
117
- │ ├── config/ # Database and Swagger configurations
118
- │ ├── controllers/ # Request handlers and business logic
119
- │ ├── middleware/ # Custom middleware (auth, validation, errors)
120
- │ ├── models/ # Database models (if using database)
121
- │ ├── routes/ # API route definitions
122
- │ ├── services/ # Business logic layer
123
- │ ├── utils/ # Utility functions and helpers
124
- │ ├── app.js # Express app setup with middleware
125
- │ └── server.js # Server entry point with clustering
126
- ├── tests/ # Jest tests for endpoints
127
- ├── .env # Environment variables
128
- ├── .eslintrc.json # ESLint configuration
129
- ├── .prettierrc # Prettier configuration
130
- ├── Dockerfile # Docker configuration
131
- ├── docker-compose.yml # Docker services (app + database)
132
- └── package.json # Dependencies and scripts
115
+ │ ├── config/ # Database and Swagger config
116
+ │ ├── controllers/ # Request handlers
117
+ │ ├── middleware/ # Auth, validation, errors
118
+ │ ├── models/ # Database models (if enabled)
119
+ │ ├── routes/ # API routes
120
+ │ ├── services/ # Business logic
121
+ │ ├── utils/ # Helper functions
122
+ │ ├── app.js # Express setup
123
+ │ └── server.js # Server entry point
124
+ ├── tests/ # Test suites
125
+ ├── .env # Environment variables
126
+ ├── Dockerfile # Container config
127
+ └── docker-compose.yml # Multi-container setup
133
128
  ```
134
129
 
135
- ## Available Scripts (Generated Project)
136
-
137
- - `npm run dev` - Start development server with nodemon
138
- - `npm start` - Start production server with clustering
139
- - `npm test` - Run Jest tests with coverage
140
- - `npm run lint` - Run ESLint checks
141
- - `npm run lint:fix` - Fix ESLint issues automatically
142
- - `npm run format` - Format code with Prettier
143
- - `npm run format:check` - Check code formatting
130
+ ## Environment Variables
144
131
 
145
- ## Contributing
132
+ Create a `.env` file (generated automatically):
146
133
 
147
- To contribute to express-genix:
148
-
149
- 1. **Fork and Clone**:
150
- ```bash
151
- git clone <your-fork-url>
152
- cd express-genix
153
- ```
154
-
155
- 2. **Install Dependencies**:
156
- ```bash
157
- npm install
158
- ```
159
-
160
- 3. **Make Changes**:
161
- - Update templates in `templates/` directory
162
- - Modify generation logic in `lib/generator.js`
163
- - Follow Airbnb JavaScript style
164
- - Test changes locally: `node index.js init`
165
- - Verify generated projects have zero linting errors
166
-
167
- 4. **Submit a Pull Request**:
168
- - Push changes and submit a PR with a clear description
169
- - Include test results showing the generated project works correctly
170
-
171
- ## Version History
172
-
173
- - **v1.1.0**: Added "No Database" option and template-based architecture with EJS
174
- - **v1.0.1**: Added automatic post-generation cleanup with Prettier and ESLint auto-fix
175
- - **v1.0.0**: Initial release with Express boilerplate generation
176
-
177
- ## Publishing to npm
178
-
179
- To publish express-genix to npm, follow these steps from the CLI's root directory:
180
-
181
- ### 1. Prepare the Project
182
-
183
- Ensure all template files are in place in the `templates/` directory structure.
184
-
185
- Verify `package.json` is configured correctly:
186
-
187
- ```json
188
- {
189
- "name": "express-genix",
190
- "version": "1.1.0",
191
- "description": "Production-grade CLI to generate Express apps with JWT, DB, rate-limiting, automatic formatting, and more",
192
- "main": "index.js",
193
- "bin": {
194
- "express-genix": "./index.js"
195
- },
196
- "dependencies": {
197
- "commander": "^12.1.0",
198
- "inquirer": "^10.2.0",
199
- "ejs": "^3.1.9"
200
- }
201
- }
134
+ ```bash
135
+ # Server
136
+ NODE_ENV=development
137
+ PORT=3000
138
+
139
+ # Database (if using MongoDB/PostgreSQL)
140
+ MONGO_URI=mongodb://localhost:27017/myapp
141
+ # or
142
+ DATABASE_URL=postgresql://user:password@localhost:5432/myapp
143
+
144
+ # JWT (if using database)
145
+ JWT_SECRET=your-secret-key
146
+ JWT_REFRESH_SECRET=your-refresh-secret
147
+ JWT_EXPIRE=15m
148
+ JWT_REFRESH_EXPIRE=7d
149
+
150
+ # Rate Limiting
151
+ RATE_LIMIT_WINDOW_MS=900000
152
+ RATE_LIMIT_MAX=100
202
153
  ```
203
154
 
204
- ### 2. Test Locally
155
+ ## Docker Deployment
205
156
 
206
- Run the CLI to ensure it generates working, properly formatted projects for all three database options:
157
+ The generated project includes Docker support:
207
158
 
208
159
  ```bash
209
- node index.js init
210
- ```
160
+ # Build and run with Docker Compose
161
+ docker-compose up
211
162
 
212
- Test each option:
213
- - MongoDB with authentication
214
- - PostgreSQL with authentication
215
- - No database with example API
163
+ # Or build manually
164
+ docker build -t my-app .
165
+ docker run -p 3000:3000 --env-file .env my-app
166
+ ```
216
167
 
217
- ### 3. Publish
168
+ ## Troubleshooting
218
169
 
219
- Login to npm and publish:
170
+ **Database Connection Issues**
171
+ - Ensure MongoDB/PostgreSQL is running
172
+ - Check connection string in `.env`
173
+ - Verify database credentials
220
174
 
175
+ **Dependency Errors**
221
176
  ```bash
222
- npm login
223
- npm publish --access public
177
+ npm cache clean --force
178
+ rm -rf node_modules package-lock.json
179
+ npm install
224
180
  ```
225
181
 
226
- ### 4. Verify
182
+ **Port Already in Use**
183
+ ```bash
184
+ # Change port in .env
185
+ PORT=3001
186
+ ```
227
187
 
228
- Test the published package:
188
+ ## CLI Options
229
189
 
230
190
  ```bash
231
- npx express-genix init
232
- # Should generate a project with zero linting errors
191
+ express-genix init --skip-cleanup # Skip auto-formatting (for debugging)
233
192
  ```
234
193
 
235
- ## Troubleshooting
236
-
237
- ### Publishing Issues
194
+ ## Contributing
238
195
 
239
- - **Name Conflict**: If `express-genix` is taken, use a scoped name like `@yourname/express-genix`
240
- - **Authentication Error**: Verify with `npm whoami`, re-login if needed
241
- - **Permission Issues**: Move project to a directory with full write access
196
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
242
197
 
243
- ### Generated Project Issues
198
+ ## Support
244
199
 
245
- - **Dependency Errors**: Run `npm cache clean --force && npm install`
246
- - **Database Connection**: Ensure MongoDB/PostgreSQL is running and connection strings are correct
247
- - **Linting Issues**: Run `npm run lint:fix && npm run format` to resolve formatting
200
+ - **Issues**: [GitHub Issues](https://github.com/yourusername/express-genix/issues)
201
+ - **Documentation**: [Full Docs](https://github.com/yourusername/express-genix)
248
202
 
249
203
  ## License
250
204
 
251
- MIT License
252
-
253
- Copyright (c) 2025 Joshua Maeba Nyamasege
254
-
255
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
205
+ MIT © [Joshua Maeba Nyamasege](LICENSE)
256
206
 
257
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
207
+ ## Changelog
258
208
 
259
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
209
+ See [CHANGELOG.md](CHANGELOG.md) for version history and release notes.
package/lib/generator.js CHANGED
@@ -126,8 +126,7 @@ const generateFiles = async (config, projectDir) => {
126
126
  if (config.hasDatabase) {
127
127
  serviceFiles.push(
128
128
  { template: 'services/authService.js.ejs', output: 'src/services/authService.js' },
129
- { template: `services/userService.${config.db === 'mongodb' ? 'mongodb' : 'postgresql'}.js.ejs`, output: 'src/services/userService.js' },
130
- );
129
+ { template: `services/userService.${config.db === 'mongodb' ? 'mongodb' : 'postgres'}.js.ejs`, output: 'src/services/userService.js' }, );
131
130
  } else {
132
131
  serviceFiles.push(
133
132
  { template: 'services/exampleService.js.ejs', output: 'src/services/exampleService.js' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-genix",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Production-grade CLI to generate Express apps with JWT, DB, rate-limiting, automatic formatting, and more",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -4,10 +4,8 @@ const mongoUri = process.env.MONGO_URI || 'mongodb://localhost:27017/<%= project
4
4
 
5
5
  const connect = async () => {
6
6
  try {
7
- await mongoose.connect(mongoUri, {
8
- useNewUrlParser: true,
9
- useUnifiedTopology: true,
10
- });
7
+ // Remove deprecated options - they're no longer needed in modern Mongoose
8
+ await mongoose.connect(mongoUri);
11
9
  console.log('MongoDB connected successfully');
12
10
  } catch (error) {
13
11
  console.error('MongoDB connection error:', error);
@@ -10,7 +10,8 @@ const startServer = async () => {<% if (hasDatabase) { %>
10
10
 
11
11
  if (cluster.isMaster) {
12
12
  const numCPUs = os.cpus().length;
13
- console.log(`Master ${process.pid} is running`);
13
+ console.log(`🚀 Master ${process.pid} is running`);
14
+ console.log(`📊 Forking ${numCPUs} workers...`);
14
15
 
15
16
  // Fork workers
16
17
  for (let i = 0; i < numCPUs; i++) {
@@ -18,12 +19,16 @@ const startServer = async () => {<% if (hasDatabase) { %>
18
19
  }
19
20
 
20
21
  cluster.on('exit', (worker, code, signal) => {
21
- console.log(`Worker ${worker.process.pid} died with code ${code} and signal ${signal}`);
22
+ console.log(`💥 Worker ${worker.process.pid} died with code ${code} and signal ${signal}`);
23
+ console.log('🔄 Starting a new worker...');
22
24
  cluster.fork();
23
25
  });
24
26
  } else {
25
27
  app.listen(port, () => {
26
- console.log(`Worker ${process.pid} running on http://localhost:${port}`);
28
+ console.log(`🌟 Worker ${process.pid} running on http://localhost:${port}`);
29
+ console.log(`📚 API Documentation: http://localhost:${port}/api-docs`);
30
+ console.log(`❤️ Health Check: http://localhost:${port}/health`);
31
+ console.log(`🛠️ Environment: ${process.env.NODE_ENV || 'development'}`);
27
32
  });
28
33
  }
29
34
  };
@@ -32,13 +37,13 @@ startServer().catch(console.error);
32
37
 
33
38
  // Graceful Shutdown
34
39
  process.on('SIGTERM', async () => {
35
- console.log('SIGTERM signal received: closing HTTP server');<% if (hasDatabase) { %>
40
+ console.log('🛑 SIGTERM signal received: closing HTTP server');<% if (hasDatabase) { %>
36
41
  await db.disconnect();<% } %>
37
42
  process.exit(0);
38
43
  });
39
44
 
40
45
  process.on('SIGINT', async () => {
41
- console.log('SIGINT signal received: closing HTTP server');<% if (hasDatabase) { %>
46
+ console.log('🛑 SIGINT signal received: closing HTTP server');<% if (hasDatabase) { %>
42
47
  await db.disconnect();<% } %>
43
48
  process.exit(0);
44
49
  });
@@ -26,8 +26,5 @@ const userSchema = new mongoose.Schema({
26
26
  timestamps: true,
27
27
  });
28
28
 
29
- // Index for better query performance
30
- userSchema.index({ email: 1 });
31
- userSchema.index({ username: 1 });
32
29
 
33
30
  module.exports = mongoose.model('User', userSchema);