@sachin-thakur/create-nodejs-app 1.0.0

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/DEVELOPMENT.md ADDED
@@ -0,0 +1,183 @@
1
+ # Development Guide
2
+
3
+ ## Testing the CLI Locally
4
+
5
+ ### 1. Link the CLI tool globally
6
+
7
+ From the `create-nodejs-app` directory:
8
+
9
+ ```bash
10
+ npm link
11
+ ```
12
+
13
+ This creates a global symlink to your CLI tool.
14
+
15
+ ### 2. Test the CLI
16
+
17
+ Now you can run your CLI from anywhere:
18
+
19
+ ```bash
20
+ create-nodejs-app test-app
21
+ ```
22
+
23
+ Or using the full command:
24
+
25
+ ```bash
26
+ node /path/to/create-nodejs-app/bin/cli.js test-app
27
+ ```
28
+
29
+ ### 3. Test in a separate directory
30
+
31
+ ```bash
32
+ cd /tmp
33
+ create-nodejs-app my-test-project
34
+ cd my-test-project
35
+ npm install
36
+ npm run dev
37
+ ```
38
+
39
+ ### 4. Unlink when done testing
40
+
41
+ ```bash
42
+ npm unlink -g create-nodejs-app
43
+ ```
44
+
45
+ ## Publishing to npm
46
+
47
+ ### 1. Create an npm account
48
+
49
+ If you don't have one: https://www.npmjs.com/signup
50
+
51
+ ### 2. Login to npm
52
+
53
+ ```bash
54
+ npm login
55
+ ```
56
+
57
+ ### 3. Update package.json
58
+
59
+ Make sure your package.json has:
60
+ - Unique name (check on npmjs.com)
61
+ - Correct version
62
+ - Your information in author field
63
+ - Repository URL
64
+
65
+ ### 4. Test the package
66
+
67
+ ```bash
68
+ npm pack
69
+ ```
70
+
71
+ This creates a .tgz file. You can test install it:
72
+
73
+ ```bash
74
+ npm install -g ./create-nodejs-app-1.0.0.tgz
75
+ ```
76
+
77
+ ### 5. Publish
78
+
79
+ ```bash
80
+ npm publish
81
+ ```
82
+
83
+ For first publish of a scoped package:
84
+ ```bash
85
+ npm publish --access public
86
+ ```
87
+
88
+ ### 6. Update versions
89
+
90
+ When you make changes:
91
+
92
+ ```bash
93
+ # Patch version (1.0.0 -> 1.0.1)
94
+ npm version patch
95
+
96
+ # Minor version (1.0.0 -> 1.1.0)
97
+ npm version minor
98
+
99
+ # Major version (1.0.0 -> 2.0.0)
100
+ npm version major
101
+
102
+ # Then publish
103
+ npm publish
104
+ ```
105
+
106
+ ## Project Structure
107
+
108
+ ```
109
+ create-nodejs-app/
110
+ ├── bin/
111
+ │ └── cli.js # CLI entry point
112
+ ├── src/
113
+ │ ├── generator.js # Main project generator
114
+ │ ├── templates/ # Code templates
115
+ │ │ ├── index.js
116
+ │ │ ├── mvc.js # MVC architecture
117
+ │ │ ├── clean.js # Clean architecture
118
+ │ │ └── featureBased.js
119
+ │ └── utils/ # Utility functions
120
+ │ ├── packageJson.js
121
+ │ ├── envFile.js
122
+ │ ├── readme.js
123
+ │ ├── docker.js
124
+ │ └── cicd.js
125
+ ├── package.json
126
+ └── README.md
127
+ ```
128
+
129
+ ## Adding New Features
130
+
131
+ ### Add a new project type
132
+
133
+ 1. Edit `bin/cli.js` - add option to projectType choices
134
+ 2. Update templates to handle the new type
135
+
136
+ ### Add a new architecture
137
+
138
+ 1. Create new file in `src/templates/` (e.g., `hexagonal.js`)
139
+ 2. Implement the structure generation
140
+ 3. Export the function
141
+ 4. Import and use in `src/templates/index.js`
142
+
143
+ ### Add a new feature
144
+
145
+ 1. Update `bin/cli.js` - add to features choices
146
+ 2. Update `src/utils/packageJson.js` - add dependencies
147
+ 3. Update `src/utils/envFile.js` - add environment variables
148
+ 4. Update template files to include the feature
149
+
150
+ ## Tips
151
+
152
+ - Test thoroughly before publishing
153
+ - Use semantic versioning
154
+ - Keep a CHANGELOG.md
155
+ - Write good commit messages
156
+ - Tag releases in git
157
+ - Monitor issues and pull requests
158
+
159
+ ## Common Issues
160
+
161
+ ### Permission denied
162
+
163
+ ```bash
164
+ chmod +x bin/cli.js
165
+ ```
166
+
167
+ ### Module not found
168
+
169
+ Make sure all requires/imports are correct and files exist.
170
+
171
+ ### npm link not working
172
+
173
+ Try:
174
+ ```bash
175
+ npm unlink
176
+ npm link
177
+ ```
178
+
179
+ Or globally:
180
+ ```bash
181
+ npm unlink -g create-nodejs-app
182
+ npm link -g
183
+ ```
package/README.md ADDED
@@ -0,0 +1,238 @@
1
+ # Create Production Node App
2
+
3
+ 🚀 A powerful CLI tool to scaffold **production-ready** Node.js applications with modern best practices, complete with TypeScript support, database integration, authentication, testing, and more.
4
+
5
+ ## ✨ Features
6
+
7
+ Unlike other scaffolding tools that give you a basic "Hello World" template, **Create Production App** generates applications that are ready for production deployment with:
8
+
9
+ - 🎯 **Multiple Project Types**: REST API, GraphQL API, Microservices, CLI Tools
10
+ - 📐 **Architecture Patterns**: MVC, Clean Architecture, Feature-based (Modular)
11
+ - 💎 **TypeScript or JavaScript**: Full TypeScript support with strict mode
12
+ - 🗄️ **Database Integration**: PostgreSQL, MongoDB, MySQL with connection pooling
13
+ - 🔐 **Authentication**: JWT-based auth with bcrypt password hashing
14
+ - ✅ **Request Validation**: Input validation with Zod
15
+ - 📝 **Logging**: Structured logging with Winston
16
+ - 📚 **API Documentation**: Auto-generated Swagger/OpenAPI docs
17
+ - 🛡️ **Security**: Rate limiting, CORS, helmet, input sanitization
18
+ - ⚡ **Caching**: Redis integration for performance
19
+ - 📧 **Email Service**: Nodemailer setup for transactional emails
20
+ - 📁 **File Upload**: Multer configuration for file handling
21
+ - 🔄 **Background Jobs**: Bull queue for async task processing
22
+ - 🧪 **Testing**: Jest, Vitest, or Mocha with example tests
23
+ - 🐳 **Docker**: Complete Docker and docker-compose setup
24
+ - 🔄 **CI/CD**: GitHub Actions workflow configured
25
+ - 📦 **ESLint & Prettier**: Code quality and formatting
26
+
27
+ ## 🚀 Quick Start
28
+
29
+ ### Using npx (Recommended)
30
+
31
+ ```bash
32
+ npx create-nodejs-app my-awesome-app
33
+ ```
34
+
35
+ ### Using npm
36
+
37
+ ```bash
38
+ npm install -g create-nodejs-app
39
+ create-nodejs-app my-awesome-app
40
+ ```
41
+
42
+ ### Using yarn
43
+
44
+ ```bash
45
+ yarn global add create-nodejs-app
46
+ create-nodejs-app my-awesome-app
47
+ ```
48
+
49
+ ## 📖 Usage
50
+
51
+ Simply run the command and follow the interactive prompts:
52
+
53
+ ```bash
54
+ npx create-nodejs-app my-app
55
+ ```
56
+
57
+ You'll be asked to choose:
58
+
59
+ 1. **Project Type**: REST API, GraphQL API, Microservice, or CLI Tool
60
+ 2. **Language**: TypeScript (recommended) or JavaScript
61
+ 3. **Architecture**: MVC, Clean Architecture, or Feature-based
62
+ 4. **Database**: PostgreSQL, MongoDB, MySQL, or None
63
+ 5. **Features**:
64
+ - Authentication (JWT)
65
+ - API Documentation (Swagger)
66
+ - Request Validation
67
+ - Error Handling & Logging
68
+ - Rate Limiting
69
+ - CORS Configuration
70
+ - File Upload
71
+ - Email Service
72
+ - Caching (Redis)
73
+ - Background Jobs
74
+ 6. **Testing Framework**: Jest, Vitest, Mocha, or None
75
+ 7. **Docker**: Include Docker configuration
76
+ 8. **CI/CD**: Include GitHub Actions workflow
77
+
78
+ ## 📦 What You Get
79
+
80
+ After running the CLI, you'll have a fully structured project:
81
+
82
+ ```
83
+ my-app/
84
+ ├── src/
85
+ │ ├── config/ # Configuration files
86
+ │ │ ├── database.ts # Database connection
87
+ │ │ ├── logger.ts # Winston logger setup
88
+ │ │ └── swagger.ts # Swagger configuration
89
+ │ ├── controllers/ # Request handlers
90
+ │ ├── models/ # Database models
91
+ │ ├── routes/ # API routes with Swagger docs
92
+ │ ├── middlewares/ # Custom middlewares (auth, validation, error handling)
93
+ │ ├── services/ # Business logic layer
94
+ │ ├── utils/ # Utility functions
95
+ │ └── index.ts # Application entry point
96
+ ├── tests/ # Test files
97
+ ├── .github/
98
+ │ └── workflows/ # CI/CD configuration
99
+ ├── Dockerfile # Docker configuration
100
+ ├── docker-compose.yml # Multi-container setup
101
+ ├── .env.example # Environment variables template
102
+ ├── .gitignore
103
+ ├── .eslintrc.json # ESLint configuration
104
+ ├── .prettierrc # Prettier configuration
105
+ ├── tsconfig.json # TypeScript configuration (if TS)
106
+ ├── package.json
107
+ └── README.md # Project-specific README
108
+ ```
109
+
110
+ ## 🎯 Example Projects
111
+
112
+ ### REST API with PostgreSQL
113
+
114
+ ```bash
115
+ npx create-nodejs-app my-api
116
+ # Select: REST API, TypeScript, MVC, PostgreSQL
117
+ # Select features: Auth, Validation, Logging, Swagger, Rate Limiting, CORS
118
+ # Select: Jest, Docker, CI/CD
119
+ ```
120
+
121
+ This generates a production-ready REST API with:
122
+ - JWT authentication
123
+ - PostgreSQL database with connection pooling
124
+ - Request validation with Zod
125
+ - Comprehensive error handling
126
+ - Swagger API documentation
127
+ - Rate limiting and CORS
128
+ - Docker setup with PostgreSQL container
129
+ - CI/CD pipeline with GitHub Actions
130
+
131
+ ### Microservice with MongoDB
132
+
133
+ ```bash
134
+ npx create-nodejs-app user-service
135
+ # Select: Microservice, TypeScript, Clean Architecture, MongoDB
136
+ # Select features: Auth, Validation, Logging, Caching, Background Jobs
137
+ # Select: Jest, Docker, CI/CD
138
+ ```
139
+
140
+ ## 🔧 Development
141
+
142
+ After creating your project:
143
+
144
+ ```bash
145
+ cd my-app
146
+ npm install
147
+ cp .env.example .env
148
+ # Edit .env with your configuration
149
+ npm run dev
150
+ ```
151
+
152
+ Your app will be running at `http://localhost:3000`
153
+
154
+ If you included Swagger, visit: `http://localhost:3000/api-docs`
155
+
156
+ ## 🐳 Using Docker
157
+
158
+ If you included Docker configuration:
159
+
160
+ ```bash
161
+ docker-compose up
162
+ ```
163
+
164
+ This will start your application along with the database and any other services (Redis, etc.)
165
+
166
+ ## 🧪 Testing
167
+
168
+ ```bash
169
+ npm test # Run tests
170
+ npm run test:watch # Watch mode
171
+ npm run test:coverage # Coverage report
172
+ ```
173
+
174
+ ## 🏗️ Architecture Patterns
175
+
176
+ ### MVC (Model-View-Controller)
177
+ Traditional and straightforward. Great for most REST APIs and web applications.
178
+
179
+ ### Clean Architecture (Layered)
180
+ Domain-driven with clear separation of concerns. Ideal for complex business logic and enterprise applications.
181
+
182
+ ### Feature-based (Modular)
183
+ Organized by features rather than technical layers. Perfect for microservices and scalable applications.
184
+
185
+ ## 🤔 Why Create Production App?
186
+
187
+ Most Node.js scaffolding tools give you a basic structure, but lack:
188
+
189
+ - ❌ Proper error handling patterns
190
+ - ❌ Logging configuration
191
+ - ❌ Security best practices
192
+ - ❌ Database setup with migrations
193
+ - ❌ Authentication implementation
194
+ - ❌ API documentation
195
+ - ❌ Testing examples
196
+ - ❌ Docker and CI/CD setup
197
+
198
+ **Create Production App** provides all of this out of the box, so you can focus on building features instead of boilerplate.
199
+
200
+ ## 📚 Documentation
201
+
202
+ For more detailed information, check out:
203
+
204
+ - [API Development Guide](docs/api-guide.md)
205
+ - [Database Setup](docs/database.md)
206
+ - [Authentication](docs/authentication.md)
207
+ - [Testing Guide](docs/testing.md)
208
+ - [Deployment](docs/deployment.md)
209
+
210
+ ## 🤝 Contributing
211
+
212
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
213
+
214
+ 1. Fork the repository
215
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
216
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
217
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
218
+ 5. Open a Pull Request
219
+
220
+ ## 📝 License
221
+
222
+ MIT License - see [LICENSE](LICENSE) file for details
223
+
224
+ ## 🙏 Acknowledgments
225
+
226
+ Built with ❤️ to help developers ship production-ready applications faster.
227
+
228
+ ## 🐛 Issues
229
+
230
+ Found a bug or have a feature request? Please open an issue on [GitHub](https://github.com/yourusername/create-nodejs-app/issues).
231
+
232
+ ## ⭐ Star Us!
233
+
234
+ If you find this tool helpful, please consider giving it a star on GitHub!
235
+
236
+ ---
237
+
238
+ **Happy coding! 🚀**
package/bin/cli.js ADDED
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require("commander");
4
+ const chalk = require("chalk");
5
+ const ora = require("ora");
6
+ const path = require("path");
7
+ const fs = require("fs-extra");
8
+ const validateProjectName = require("validate-npm-package-name");
9
+ const { generateProject } = require("../src/generator");
10
+
11
+ program
12
+ .version("1.0.0")
13
+ .argument("[project-name]", "Name of the project")
14
+ .description("Create a production-ready Node.js application")
15
+ .action(async (projectName) => {
16
+ // ✅ FIX: Dynamic import for Inquirer (ESM-only)
17
+ const inquirer = (await import("inquirer")).default;
18
+
19
+ console.log(chalk.bold.cyan("\n🚀 Welcome to Create Production App!\n"));
20
+
21
+ // Get project name if not provided
22
+ if (!projectName) {
23
+ const answers = await inquirer.prompt([
24
+ {
25
+ type: "input",
26
+ name: "projectName",
27
+ message: "What is your project name?",
28
+ default: "my-app",
29
+ validate: (input) => {
30
+ const validation = validateProjectName(input);
31
+ if (validation.validForNewPackages) {
32
+ return true;
33
+ }
34
+ return validation.errors?.[0] || "Invalid project name";
35
+ },
36
+ },
37
+ ]);
38
+
39
+ projectName = answers.projectName;
40
+ }
41
+
42
+ // Validate project name
43
+ const validation = validateProjectName(projectName);
44
+ if (!validation.validForNewPackages) {
45
+ console.error(
46
+ chalk.red(`\n❌ Invalid project name: ${validation.errors?.[0]}\n`)
47
+ );
48
+ process.exit(1);
49
+ }
50
+
51
+ const projectPath = path.resolve(process.cwd(), projectName);
52
+
53
+ // Check if directory already exists
54
+ if (fs.existsSync(projectPath)) {
55
+ console.error(
56
+ chalk.red(`\n❌ Directory "${projectName}" already exists!\n`)
57
+ );
58
+ process.exit(1);
59
+ }
60
+
61
+ // Interactive prompts
62
+ const config = await inquirer.prompt([
63
+ {
64
+ type: "list",
65
+ name: "projectType",
66
+ message: "What type of project do you want to create?",
67
+ choices: [
68
+ { name: "REST API", value: "rest-api" },
69
+ { name: "GraphQL API", value: "graphql-api" },
70
+ { name: "Microservice", value: "microservice" },
71
+ { name: "CLI Tool", value: "cli" },
72
+ ],
73
+ default: "rest-api",
74
+ },
75
+ {
76
+ type: "list",
77
+ name: "language",
78
+ message: "Which language do you want to use?",
79
+ choices: [
80
+ { name: "TypeScript (Recommended)", value: "typescript" },
81
+ { name: "JavaScript", value: "javascript" },
82
+ ],
83
+ default: "typescript",
84
+ },
85
+ {
86
+ type: "list",
87
+ name: "architecture",
88
+ message: "Choose your project architecture:",
89
+ choices: [
90
+ { name: "MVC (Model-View-Controller)", value: "mvc" },
91
+ { name: "Clean Architecture (Layered)", value: "clean" },
92
+ { name: "Feature-based (Modular)", value: "feature-based" },
93
+ ],
94
+ default: "mvc",
95
+ },
96
+ {
97
+ type: "list",
98
+ name: "database",
99
+ message: "Which database do you want to use?",
100
+ choices: [
101
+ { name: "PostgreSQL", value: "postgresql" },
102
+ { name: "MongoDB", value: "mongodb" },
103
+ { name: "MySQL", value: "mysql" },
104
+ { name: "None", value: "none" },
105
+ ],
106
+ default: "postgresql",
107
+ },
108
+ {
109
+ type: "checkbox",
110
+ name: "features",
111
+ message: "Select additional features:",
112
+ choices: [
113
+ { name: "Authentication (JWT)", value: "auth", checked: true },
114
+ {
115
+ name: "API Documentation (Swagger)",
116
+ value: "swagger",
117
+ checked: true,
118
+ },
119
+ { name: "Request Validation", value: "validation", checked: true },
120
+ { name: "Error Handling & Logging", value: "logging", checked: true },
121
+ { name: "Rate Limiting", value: "rate-limit", checked: true },
122
+ { name: "CORS Configuration", value: "cors", checked: true },
123
+ { name: "File Upload", value: "file-upload" },
124
+ { name: "Email Service", value: "email" },
125
+ { name: "Caching (Redis)", value: "cache" },
126
+ { name: "Background Jobs", value: "jobs" },
127
+ ],
128
+ },
129
+ {
130
+ type: "list",
131
+ name: "testing",
132
+ message: "Which testing framework?",
133
+ choices: [
134
+ { name: "Jest", value: "jest" },
135
+ { name: "Vitest", value: "vitest" },
136
+ { name: "Mocha + Chai", value: "mocha" },
137
+ { name: "None", value: "none" },
138
+ ],
139
+ default: "jest",
140
+ },
141
+ {
142
+ type: "confirm",
143
+ name: "docker",
144
+ message: "Include Docker configuration?",
145
+ default: true,
146
+ },
147
+ {
148
+ type: "confirm",
149
+ name: "cicd",
150
+ message: "Include CI/CD configuration (GitHub Actions)?",
151
+ default: true,
152
+ },
153
+ ]);
154
+
155
+ // Generate project
156
+ const spinner = ora("Creating your project...").start();
157
+
158
+ try {
159
+ await generateProject(projectName, projectPath, config);
160
+ spinner.succeed(chalk.green("Project created successfully!"));
161
+
162
+ console.log(chalk.bold.cyan("\n📦 Next steps:\n"));
163
+ console.log(` cd ${projectName}`);
164
+ console.log(" npm install");
165
+ console.log(" cp .env.example .env");
166
+ console.log(" # Configure your .env file");
167
+ console.log(" npm run dev");
168
+
169
+ console.log(chalk.bold.cyan("\n✨ Happy coding!\n"));
170
+ } catch (error) {
171
+ spinner.fail(chalk.red("Failed to create project"));
172
+ console.error(chalk.red(error.message));
173
+ process.exit(1);
174
+ }
175
+ });
176
+
177
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@sachin-thakur/create-nodejs-app",
3
+ "version": "1.0.0",
4
+ "description": "A CLI tool to scaffold production-ready Node.js applications with best practices",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "create-nodejs-app": "./bin/cli.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [
13
+ "cli",
14
+ "scaffolding",
15
+ "nodejs",
16
+ "typescript",
17
+ "boilerplate",
18
+ "production-ready",
19
+ "api",
20
+ "rest",
21
+ "starter"
22
+ ],
23
+ "author": "Your Name",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "commander": "^11.1.0",
27
+ "inquirer": "^9.2.12",
28
+ "chalk": "^4.1.2",
29
+ "ora": "^5.4.1",
30
+ "fs-extra": "^11.2.0",
31
+ "validate-npm-package-name": "^5.0.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=16.0.0"
35
+ }
36
+ }