backend-scaffold-cli 1.4.0 → 1.5.1
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/README.md +66 -24
- package/bin/cli.js +82 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
|
|
1
2
|
# backend-scaffold-cli
|
|
2
3
|
|
|
3
|
-
A CLI tool to quickly scaffold Express.js backend projects with MongoDB, middleware, and common setup. It automatically generates production-ready projects with JWT authentication, error handling, request logging, input validation, DNS configuration, and pre-configured MongoDB Atlas connection.
|
|
4
|
+
A CLI tool to quickly scaffold Express.js backend projects with MongoDB, middleware, and common setup. It automatically generates production-ready projects with JWT authentication, error handling, request logging, input validation, DNS configuration, and pre-configured MongoDB Atlas connection. Every project has different requirements, so this tool provides a solid, common foundation that developers can easily modify, extend, or trim according to their specific needs.
|
|
4
5
|
|
|
5
6
|
## Features
|
|
6
7
|
|
|
@@ -13,13 +14,17 @@ A CLI tool to quickly scaffold Express.js backend projects with MongoDB, middlew
|
|
|
13
14
|
|
|
14
15
|
🔐 **Security**
|
|
15
16
|
- JWT authentication middleware
|
|
17
|
+
- Password hashing with bcryptjs
|
|
16
18
|
- Error handling middleware
|
|
17
19
|
- CORS configuration
|
|
20
|
+
- Rate limiting (optional)
|
|
18
21
|
|
|
19
22
|
📝 **Developer Experience**
|
|
20
23
|
- Logging middleware
|
|
21
|
-
- Input validation
|
|
22
|
-
-
|
|
24
|
+
- Input validation (optional)
|
|
25
|
+
- File upload support with multer (optional)
|
|
26
|
+
- Axios utility for external API calls (optional)
|
|
27
|
+
- Sample routes and User model
|
|
23
28
|
- Git initialization
|
|
24
29
|
- Auto dependency installation
|
|
25
30
|
|
|
@@ -38,55 +43,92 @@ npm install -g backend-scaffold-cli
|
|
|
38
43
|
create-express-backend my-app
|
|
39
44
|
```
|
|
40
45
|
|
|
46
|
+
> **Tip:** Always use `@latest` to ensure you get the newest version with all features and bug fixes.
|
|
47
|
+
|
|
41
48
|
## Usage
|
|
42
49
|
|
|
43
50
|
```bash
|
|
44
|
-
npx backend-scaffold-cli <project-name>
|
|
51
|
+
npx backend-scaffold-cli@latest <project-name>
|
|
45
52
|
```
|
|
46
53
|
|
|
47
54
|
You'll be prompted to select features:
|
|
48
|
-
- ✅ Include JWT authentication
|
|
49
|
-
- ✅ Include logging middleware
|
|
55
|
+
- ✅ Include JWT authentication (adds bcryptjs + User model)
|
|
50
56
|
- ✅ Include input validation
|
|
57
|
+
- ✅ Include rate limiting
|
|
58
|
+
- ✅ Include file upload support (multer)
|
|
59
|
+
- ✅ Include axios (for external API calls)
|
|
51
60
|
- ✅ Install dependencies
|
|
52
61
|
|
|
62
|
+
After setup, copy `.env.example` to `.env`, configure your MongoDB URI, then run:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm start
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Test it's working:
|
|
69
|
+
```bash
|
|
70
|
+
curl http://localhost:5000/api/health
|
|
71
|
+
```
|
|
72
|
+
|
|
53
73
|
## Project Structure
|
|
74
|
+
|
|
54
75
|
```
|
|
55
76
|
my-app/
|
|
56
77
|
├── src/
|
|
57
|
-
│
|
|
58
|
-
│
|
|
59
|
-
│
|
|
60
|
-
│
|
|
61
|
-
│
|
|
62
|
-
│
|
|
63
|
-
│
|
|
78
|
+
│ ├── config/
|
|
79
|
+
│ │ └── db.js
|
|
80
|
+
│ ├── middleware/
|
|
81
|
+
│ │ ├── errorHandler.js
|
|
82
|
+
│ │ ├── logger.js
|
|
83
|
+
│ │ ├── auth.js
|
|
84
|
+
│ │ ├── validation.js
|
|
85
|
+
│ │ ├── rateLimiter.js
|
|
86
|
+
│ │ └── upload.js
|
|
87
|
+
│ ├── routes/
|
|
88
|
+
│ │ └── index.js
|
|
89
|
+
│ ├── controllers/
|
|
90
|
+
│ ├── models/
|
|
91
|
+
│ │ └── User.js
|
|
92
|
+
│ ├── utils/
|
|
93
|
+
│ │ └── axiosUtil.js
|
|
94
|
+
│ ├── validation/
|
|
95
|
+
│ └── server.js
|
|
96
|
+
├── uploads/
|
|
64
97
|
├── .env.example
|
|
65
98
|
├── .gitignore
|
|
66
99
|
└── package.json
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Quick Start
|
|
70
100
|
|
|
71
|
-
```bash
|
|
72
|
-
npx backend-scaffold-cli my-app
|
|
73
|
-
cd my-app
|
|
74
|
-
cp .env.example .env
|
|
75
|
-
npm start
|
|
76
101
|
```
|
|
77
102
|
|
|
78
|
-
Visit: `http://localhost:5000/api/health`
|
|
79
103
|
|
|
80
104
|
## Environment Variables
|
|
81
105
|
|
|
82
106
|
```env
|
|
107
|
+
# Server Configuration
|
|
83
108
|
PORT=5000
|
|
84
109
|
NODE_ENV=development
|
|
110
|
+
|
|
111
|
+
# MongoDB Configuration
|
|
85
112
|
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/dbname
|
|
86
|
-
|
|
113
|
+
DB_NAME=myapp
|
|
114
|
+
|
|
115
|
+
# DNS Configuration
|
|
87
116
|
DNS_SERVERS=8.8.8.8,8.8.4.4
|
|
117
|
+
|
|
118
|
+
# JWT Configuration
|
|
119
|
+
JWT_SECRET=your-secret-key-change-this-in-production
|
|
120
|
+
JWT_EXPIRE=7d
|
|
121
|
+
|
|
122
|
+
# CORS
|
|
123
|
+
CORS_ORIGIN=http://localhost:3000
|
|
88
124
|
```
|
|
89
125
|
|
|
126
|
+
|
|
127
|
+
|
|
90
128
|
## License
|
|
91
129
|
|
|
92
|
-
MIT
|
|
130
|
+
MIT
|
|
131
|
+
|
|
132
|
+
## Repository
|
|
133
|
+
|
|
134
|
+
https://github.com/abhi-0605/express-backend
|
package/bin/cli.js
CHANGED
|
@@ -48,6 +48,12 @@ program
|
|
|
48
48
|
name: 'installDeps',
|
|
49
49
|
message: 'Install dependencies now?',
|
|
50
50
|
default: true
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'confirm',
|
|
54
|
+
name: 'useAxios',
|
|
55
|
+
message: 'Include axios (for external API calls)?',
|
|
56
|
+
default: true
|
|
51
57
|
}
|
|
52
58
|
]);
|
|
53
59
|
|
|
@@ -74,6 +80,9 @@ program
|
|
|
74
80
|
if (answers.useAuth) {
|
|
75
81
|
createUserModel(projectPath);
|
|
76
82
|
}
|
|
83
|
+
if(answers.useAxios){
|
|
84
|
+
createAxiosUtil(projectPath);
|
|
85
|
+
}
|
|
77
86
|
|
|
78
87
|
console.log(chalk.cyan(' Initializing git repository...'));
|
|
79
88
|
execSync('git init', { cwd: projectPath });
|
|
@@ -149,6 +158,7 @@ const createConfigFiles = (projectPath, answers) => {
|
|
|
149
158
|
...(answers.useValidation && { joi: '^17.9.0' }),
|
|
150
159
|
...(answers.useRateLimit && { 'express-rate-limit': '^6.7.0' }),
|
|
151
160
|
...(answers.useFileUpload && { multer: '^2.0.0' }),
|
|
161
|
+
...(answers.useAxios && { axios: '^1.6.0' }),
|
|
152
162
|
|
|
153
163
|
},
|
|
154
164
|
devDependencies: {
|
|
@@ -664,4 +674,76 @@ function createUserModel(projectPath) {
|
|
|
664
674
|
)
|
|
665
675
|
|
|
666
676
|
console.log(chalk.green('User model created'));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
function createAxiosUtil(projectPath){
|
|
683
|
+
const axiosUtil = ` const axios = require('axios');
|
|
684
|
+
|
|
685
|
+
//create an axios instance with default config
|
|
686
|
+
const axiosInstance = axios.create({
|
|
687
|
+
baseURL: process.env.API_BASE_URL || '',
|
|
688
|
+
timeout: 10000,
|
|
689
|
+
headers:{
|
|
690
|
+
'Content-Type' : 'application/json',
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
//request interceptor
|
|
695
|
+
axiosInstance.interceptors.request.use(
|
|
696
|
+
(config) =>{
|
|
697
|
+
console.log(\`Making request to: \${config.url}\`);;
|
|
698
|
+
return config;
|
|
699
|
+
},
|
|
700
|
+
(error) => Promise.reject(error)
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
//response interceptor
|
|
704
|
+
axiosInstance.interceptors.response.use(
|
|
705
|
+
(response) => response,
|
|
706
|
+
(error) => {
|
|
707
|
+
console.error('API call error: ', error.response ? error.response.data : error.message);
|
|
708
|
+
return Promise.reject(error);
|
|
709
|
+
}
|
|
710
|
+
);
|
|
711
|
+
|
|
712
|
+
//fetch data function
|
|
713
|
+
const fetchData = async (url) => {
|
|
714
|
+
try{
|
|
715
|
+
const response = await axiosInstance.get(url);
|
|
716
|
+
return response.data;
|
|
717
|
+
}catch(error){
|
|
718
|
+
throw new Error(\`Failed to fetch data: \${error.message}\`);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
//post data function
|
|
723
|
+
const postData = async (url, data) => {
|
|
724
|
+
try{
|
|
725
|
+
const response = await axiosInstance.post(url, data);
|
|
726
|
+
return response.data;
|
|
727
|
+
}catch(error){
|
|
728
|
+
throw new Error(\`Failed to post data: \${error.message}\`);
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
module.exports = {
|
|
733
|
+
axiosInstance,
|
|
734
|
+
fetchData,
|
|
735
|
+
postData,
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
`;
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
fs.writeFileSync(
|
|
744
|
+
path.join(projectPath, 'src/utils/axiosUtil.js'),
|
|
745
|
+
axiosUtil
|
|
746
|
+
);
|
|
747
|
+
|
|
748
|
+
console.log(chalk.green('Axios utility created'));
|
|
667
749
|
}
|