create-server-nodejs 1.0.6 → 1.0.8
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/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-server-nodejs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "server.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/captainulfur/create-server-nodejs"
|
|
8
|
+
},
|
|
6
9
|
"scripts": {
|
|
7
10
|
"start": "node server.js",
|
|
8
11
|
"dev": "nodemon server.js"
|
|
@@ -37,6 +40,7 @@
|
|
|
37
40
|
"mongoose": "^9.4.1",
|
|
38
41
|
"morgan": "^1.10.1",
|
|
39
42
|
"multer": "^2.1.1",
|
|
40
|
-
"nodemon": "^3.1.14"
|
|
43
|
+
"nodemon": "^3.1.14",
|
|
44
|
+
"sequelize": "^6.37.8"
|
|
41
45
|
}
|
|
42
46
|
}
|
|
@@ -57,59 +57,76 @@ folders.forEach(folder => {
|
|
|
57
57
|
|
|
58
58
|
const files = {
|
|
59
59
|
'server.js': `import { app } from "./app.js";
|
|
60
|
-
import dotenv from "dotenv";
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
import dotenv from "dotenv";
|
|
61
|
+
${isPostgres ? `import { Sequelize } from "sequelize";` : `import mongoose from "mongoose";`}
|
|
62
|
+
|
|
63
|
+
dotenv.config();
|
|
64
|
+
|
|
65
|
+
const PORT = process.env.PORT || 5000;
|
|
66
|
+
|
|
67
|
+
app.listen(PORT, () => {
|
|
68
|
+
console.log(\`⚡ Server is running on port \${PORT}\`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
${isPostgres ? `
|
|
72
|
+
const sequelize = new Sequelize(process.env.DATABASE_URL, {
|
|
73
|
+
dialect: "postgres",
|
|
74
|
+
logging: false,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await sequelize.authenticate();
|
|
78
|
+
console.log("⚡ Connected to PostgreSQL");
|
|
79
|
+
`: `
|
|
80
|
+
mongoose.connect(process.env.DATABASE_URL)
|
|
81
|
+
.then(() => {
|
|
82
|
+
console.log("⚡ Connected to MongoDB");
|
|
83
|
+
})
|
|
84
|
+
.catch((error) => {
|
|
85
|
+
console.log("❌ Error connecting to MongoDB:", error);
|
|
86
|
+
});
|
|
87
|
+
`}
|
|
88
|
+
`,
|
|
72
89
|
|
|
73
90
|
'app.js': `import express from "express";
|
|
74
|
-
import morgan from "morgan";
|
|
75
|
-
import cors from "cors";
|
|
91
|
+
import morgan from "morgan";
|
|
92
|
+
import cors from "cors";
|
|
76
93
|
|
|
77
|
-
const app = express();
|
|
94
|
+
const app = express();
|
|
78
95
|
|
|
79
|
-
app.use(express.json());
|
|
80
|
-
app.use(express.urlencoded({ extended: true }));
|
|
81
|
-
app.use(morgan("dev"));
|
|
82
|
-
app.use(cors());
|
|
96
|
+
app.use(express.json());
|
|
97
|
+
app.use(express.urlencoded({ extended: true }));
|
|
98
|
+
app.use(morgan("dev"));
|
|
99
|
+
app.use(cors());
|
|
83
100
|
|
|
84
|
-
import userRouter from "./Routers/user.routes.js";
|
|
101
|
+
import userRouter from "./Routers/user.routes.js";
|
|
85
102
|
|
|
86
|
-
app.use("/api/users", userRouter);
|
|
103
|
+
app.use("/api/users", userRouter);
|
|
87
104
|
|
|
88
|
-
app.get("/", (req, res) => {
|
|
89
|
-
|
|
90
|
-
});
|
|
105
|
+
app.get("/", (req, res) => {
|
|
106
|
+
res.json({ message: "Welcome to the API 🚀" });
|
|
107
|
+
});
|
|
91
108
|
|
|
92
|
-
export { app };
|
|
93
|
-
`,
|
|
109
|
+
export { app };
|
|
110
|
+
`,
|
|
94
111
|
|
|
95
112
|
'.env.example': `PORT=5000
|
|
96
|
-
${isPostgres ?
|
|
97
|
-
`DATABASE_URL="postgresql://username:password@localhost:5432/${isCurrentDir ? path.basename(process.cwd()) : projectName}?schema=public"` :
|
|
98
|
-
`
|
|
99
|
-
JWT_SECRET=your_jwt_secret_key_here
|
|
100
|
-
`,
|
|
113
|
+
${isPostgres ?
|
|
114
|
+
`DATABASE_URL="postgresql://username:password@localhost:5432/${isCurrentDir ? path.basename(process.cwd()) : projectName}?schema=public"` :
|
|
115
|
+
`DATABASE_URL=mongodb://localhost:27017/${isCurrentDir ? path.basename(process.cwd()) : projectName}`}
|
|
116
|
+
JWT_SECRET=your_jwt_secret_key_here
|
|
117
|
+
`,
|
|
101
118
|
|
|
102
119
|
'package.json': `{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
"name": "${isCurrentDir ? path.basename(process.cwd()) : projectName}",
|
|
121
|
+
"version": "1.0.0",
|
|
122
|
+
"description": "Express backend with ${isPostgres ? 'PostgreSQL + Prisma' : 'MongoDB + Mongoose'}",
|
|
123
|
+
"main": "server.js",
|
|
124
|
+
"type": "module",
|
|
125
|
+
"scripts": {
|
|
109
126
|
"start": "node server.js",
|
|
110
127
|
"dev": "nodemon server.js"
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
},
|
|
129
|
+
"dependencies": {
|
|
113
130
|
"bcryptjs": "^2.4.3",
|
|
114
131
|
"cors": "^2.8.5",
|
|
115
132
|
"dotenv": "^16.4.5",
|
|
@@ -120,62 +137,62 @@ JWT_SECRET=your_jwt_secret_key_here
|
|
|
120
137
|
`,\n "@prisma/client": "^5.15.0",
|
|
121
138
|
"prisma": "^5.15.0"` :
|
|
122
139
|
`,\n "mongoose": "^8.3.1"`}
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
},
|
|
141
|
+
"devDependencies": {
|
|
125
142
|
"nodemon": "^3.1.0"
|
|
126
|
-
|
|
127
|
-
}`,
|
|
143
|
+
}
|
|
144
|
+
}`,
|
|
128
145
|
|
|
129
146
|
'README.md': `# ${isCurrentDir ? path.basename(process.cwd()) : projectName}
|
|
130
147
|
|
|
131
|
-
A clean Node.js Express backend scaffolded with [create-server-nodejs](https://www.npmjs.com/package/create-server-nodejs).
|
|
148
|
+
A clean Node.js Express backend scaffolded with [create-server-nodejs](https://www.npmjs.com/package/create-server-nodejs).
|
|
132
149
|
|
|
133
|
-
---
|
|
150
|
+
---
|
|
134
151
|
|
|
135
|
-
## Quick Start
|
|
152
|
+
## Quick Start
|
|
136
153
|
|
|
137
|
-
\`\`\`bash
|
|
138
|
-
cp .env.example .env
|
|
139
|
-
npm run dev
|
|
140
|
-
\`\`\`
|
|
154
|
+
\`\`\`bash
|
|
155
|
+
cp .env.example .env
|
|
156
|
+
npm run dev
|
|
157
|
+
\`\`\`
|
|
141
158
|
|
|
142
|
-
---
|
|
159
|
+
---
|
|
143
160
|
|
|
144
|
-
## Folder Structure
|
|
161
|
+
## Folder Structure
|
|
145
162
|
|
|
146
|
-
- **Controllers/** → Application logic
|
|
147
|
-
- **Models/** → Database models
|
|
148
|
-
- **Routers/** → API routes
|
|
149
|
-
- **Middlewares/** → Authentication & middlewares
|
|
150
|
-
- **Utils/** → Helper functions
|
|
163
|
+
- **Controllers/** → Application logic
|
|
164
|
+
- **Models/** → Database models
|
|
165
|
+
- **Routers/** → API routes
|
|
166
|
+
- **Middlewares/** → Authentication & middlewares
|
|
167
|
+
- **Utils/** → Helper functions
|
|
151
168
|
|
|
152
|
-
---
|
|
169
|
+
---
|
|
153
170
|
|
|
154
|
-
**Database:** ${isPostgres ? 'PostgreSQL + Prisma' : 'MongoDB + Mongoose'}
|
|
171
|
+
**Database:** ${isPostgres ? 'PostgreSQL + Prisma' : 'MongoDB + Mongoose'}
|
|
155
172
|
|
|
156
|
-
Happy coding! ✨
|
|
157
|
-
`,
|
|
173
|
+
Happy coding! ✨
|
|
174
|
+
`,
|
|
158
175
|
|
|
159
176
|
'Routers/user.routes.js': `import express from "express";
|
|
160
|
-
const router = express.Router();
|
|
177
|
+
const router = express.Router();
|
|
161
178
|
|
|
162
|
-
router.get("/", (req, res) => {
|
|
163
|
-
|
|
164
|
-
});
|
|
179
|
+
router.get("/", (req, res) => {
|
|
180
|
+
res.json({ message: "User routes working!" });
|
|
181
|
+
});
|
|
165
182
|
|
|
166
|
-
export default router;
|
|
167
|
-
`,
|
|
183
|
+
export default router;
|
|
184
|
+
`,
|
|
168
185
|
|
|
169
186
|
'Middlewares/auth.middleware.js': `export const protect = (req, res, next) => {
|
|
170
187
|
console.log("Auth middleware called");
|
|
171
188
|
next();
|
|
172
|
-
};
|
|
173
|
-
`,
|
|
189
|
+
};
|
|
190
|
+
`,
|
|
174
191
|
|
|
175
192
|
'Utils/helpers.js': `export const generateRandomString = (length = 8) => {
|
|
176
193
|
return Math.random().toString(36).substring(2, length + 2);
|
|
177
|
-
};
|
|
178
|
-
`
|
|
194
|
+
};
|
|
195
|
+
`
|
|
179
196
|
};
|
|
180
197
|
|
|
181
198
|
// Write all files
|
|
@@ -232,4 +249,4 @@ console.log(chalk.bold.green('\n🎉 Project created successfully!'));
|
|
|
232
249
|
if (!isCurrentDir) {
|
|
233
250
|
console.log(chalk.cyan(`\n cd ${projectName}`));
|
|
234
251
|
}
|
|
235
|
-
console.log(chalk.cyan(` npm run dev\n`));
|
|
252
|
+
console.log(chalk.cyan(` npm run dev\n`));
|