-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateBackendStructure.js
More file actions
68 lines (63 loc) · 2.27 KB
/
createBackendStructure.js
File metadata and controls
68 lines (63 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('fs');
const path = require('path');
const projectStructure = {
'config': {
'db.js': '// Database configuration\n'
},
'controllers': {
'userController.js': '// User controller\n',
'adController.js': '// Advertisement controller\n',
'bookmarkController.js': '// Bookmark controller\n'
},
'middleware': {
'errorHandler.js': '// Error handling middleware\n'
},
'models': {
'userModel.js': '// User model\n',
'adModel.js': '// Advertisement model\n',
'bookmarkModel.js': '// Bookmark model\n'
},
'routes': {
'userRoutes.js': '// User routes\n',
'adRoutes.js': '// Advertisement routes\n',
'bookmarkRoutes.js': '// Bookmark routes\n'
},
'.env': '# Environment variables\nDB_HOST=localhost\nDB_USER=your_mysql_user\nDB_PASSWORD=your_mysql_password\nDB_NAME=divar_app\nPORT=3000\n',
'server.js': '// Main server file\n',
'package.json': JSON.stringify({
name: 'divar-backend',
version: '1.0.0',
description: 'Backend for a Divar-like application',
main: 'server.js',
scripts: {
start: 'node server.js',
dev: 'nodemon server.js'
},
dependencies: {
dotenv: '^16.0.3',
express: '^4.18.2',
'express-validator': '^7.0.1',
mysql2: '^3.2.0'
},
devDependencies: {
nodemon: '^2.0.22'
}
}, null, 2),
'README.md': '# Divar Backend\n\nBackend for a Divar-like application using Node.js, Express, and MySQL.\n\n## Setup\n\n1. Clone the repository\n2. Install dependencies: `npm install`\n3. Create a `.env` file and configure it\n4. Ensure MySQL is running and the database is set up\n5. Run the server: `npm start` or `npm run dev`\n'
};
function createStructure(basePath, structure) {
Object.keys(structure).forEach((key) => {
const fullPath = path.join(basePath, key);
if (typeof structure[key] === 'object') {
// ایجاد پوشه
fs.mkdirSync(fullPath, { recursive: true });
createStructure(fullPath, structure[key]);
} else {
fs.writeFileSync(fullPath, structure[key]);
}
});
}
const projectPath = path.join(process.cwd(), 'divar-backend');
fs.mkdirSync(projectPath, { recursive: true });
createStructure(projectPath, projectStructure);
console.log('Project structure created successfully in divar-backend!');