create-uk-node-server 1.0.1 → 1.0.2

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 CHANGED
@@ -4,7 +4,7 @@ A command-line tool to quickly scaffold server projects with JavaScript or TypeS
4
4
 
5
5
  ## Installation
6
6
  ```bash
7
- npx create-node-server
7
+ npx create-uk-node-server
8
8
  ```
9
9
 
10
10
  The tool will prompt you to:
@@ -27,16 +27,24 @@ After running the tool, you'll get a project with this structure:
27
27
  ```
28
28
  your-project/
29
29
  ├── src/
30
+ │ ├── config/
31
+ │ │ └── db.config.js
30
32
  │ ├── controllers/
33
+ │ │ └── index.controller.js
31
34
  │ ├── middlewares/
35
+ │ │ └── errorHandler.js
32
36
  │ ├── models/
37
+ │ │ └── user.model.js
33
38
  │ ├── routes/
34
39
  │ │ └── index.route.js
40
+ │ │ └── user.route.js
35
41
  │ └── utils/
36
- │ ├── db.config.js
37
42
  │ └── general.js
38
- ├── package.json
39
- └── .env
43
+ ├── .env
44
+ ├── .gitignore
45
+ ├── index.js
46
+ ├── package-lock.json
47
+ └── package.json
40
48
  ```
41
49
 
42
50
  ## Getting Started
@@ -45,7 +53,14 @@ your-project/
45
53
  2. Choose your language preference
46
54
  3. Enter your project name
47
55
  4. Navigate to your project directory
48
- 5. Update the database connection in the `.env` file
56
+ 5. Create `.env` file
57
+
58
+ ```
59
+ APP_ENV=development
60
+ APP_PORT=3000
61
+ APP_URL=http://localhost:3000
62
+ DB_URL=mongodb://localhost:27017/your-database
63
+ ```
49
64
  6. Run `npm start` to start your server
50
65
 
51
66
  ## License
package/index.js CHANGED
@@ -22,12 +22,8 @@ async function main() {
22
22
  ]);
23
23
 
24
24
  const templatePath = path.join(__dirname, "templates", answers.language.toLowerCase());
25
- // const projectPath = path.join(__dirname, answers.projectName);
26
25
  const projectPath = path.join(process.cwd(), answers.projectName);
27
26
 
28
- console.log("templatePath--------->", templatePath)
29
- console.log("projectPath---------->", projectPath)
30
-
31
27
  fs.copy(templatePath, projectPath, err => {
32
28
  if (err) return console.error(err)
33
29
  console.log('success!')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-uk-node-server",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A CLI tool to quickly scaffold server projects with JavaScript or TypeScript templates",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  import express from "express"
2
- import { connectDB } from "./src/utils/db.config.js"
3
- import indexRoutes from "./src/routes/index.route.js"
2
+ import { connectDB } from "./src/config/db.config.js"
3
+ import indexRoutes from "./src/routes/index.routes.js"
4
4
  import { errorHandler } from "./src/middlewares/errorHandler.js"
5
5
 
6
6
  const app = express()
@@ -10,14 +10,14 @@ app.use(express.json());
10
10
  app.use(express.urlencoded({ extended: true }));
11
11
  app.use(errorHandler);
12
12
 
13
+ app.use("/api", indexRoutes)
13
14
 
14
- app.use("/", indexRoutes)
15
-
16
- connectDB().then(() => {
17
- app.listen(PORT, () => {
18
- console.log(`Server is running on port ${PORT}`)
19
- })
20
- }).catch((error) => {
21
- console.error("Error connecting to MongoDB:", error)
22
- process.exit(1)
23
- })
15
+ connectDB()
16
+ .then(() => {
17
+ app.listen(PORT, () => {
18
+ console.log(`Server is running on port ${PORT}`)
19
+ })
20
+ }).catch((error) => {
21
+ console.error("Error connecting to MongoDB:", error)
22
+ process.exit(1)
23
+ })
@@ -19,4 +19,4 @@
19
19
  "mongoose": "^8.15.0",
20
20
  "nodemon": "^3.1.10"
21
21
  }
22
- }
22
+ }
@@ -0,0 +1,10 @@
1
+ import { errorResponse, successResponse } from "../utils/general.js"
2
+
3
+ export const test = async (req, res) => {
4
+ try {
5
+ return res.json(successResponse("Hello from test"))
6
+ } catch (error) {
7
+ console.log("Error in test--------->", error)
8
+ return res.json(errorResponse("Something went wrong"))
9
+ }
10
+ }
@@ -12,15 +12,11 @@ const userSchema = new mongoose.Schema({
12
12
  },
13
13
  email: {
14
14
  type: String,
15
- required: true,
16
- trim: true,
17
- unique: true,
18
- lowercase: true,
15
+ required: true
19
16
  },
20
17
  password: {
21
18
  type: String,
22
- required: true,
23
- minlength: [8, "Password must be at least 8 characters long"],
19
+ required: true
24
20
  },
25
21
  role: {
26
22
  type: Number,
@@ -0,0 +1,9 @@
1
+ import express from "express";
2
+ import { test } from "../controllers/index.controller.js"
3
+ import userRouter from "./uesr.routes.js"
4
+ const router = express.Router();
5
+
6
+ router.get("/test", test);
7
+ router.use("/users", userRouter)
8
+
9
+ export default router;
@@ -0,0 +1,11 @@
1
+ import express from "express"
2
+
3
+ const router = express.Router()
4
+
5
+ router.get("/list", (req, res) => {
6
+ return res.json({
7
+ message: "users Found Successfully..."
8
+ })
9
+ })
10
+
11
+ export default router
@@ -3,9 +3,9 @@ import mongoose from "mongoose";
3
3
  const userRole = {
4
4
  ADMIN: 1,
5
5
  USER: 2,
6
- }
6
+ } as const;
7
7
 
8
- const userSchema = new mongoose.Schema({
8
+ const userSchema = new mongoose.Schema<IUser>({
9
9
  name: {
10
10
  type: String,
11
11
  required: true
@@ -29,5 +29,13 @@ const userSchema = new mongoose.Schema({
29
29
  }
30
30
  }, { timestamps: true });
31
31
 
32
- const User = mongoose.model("User", userSchema);
32
+ const User: mongoose.Model<IUser> = mongoose.model("User", userSchema);
33
+
34
+ export interface IUser extends mongoose.Document {
35
+ name: string;
36
+ email: string;
37
+ password: string;
38
+ role: number;
39
+ }
40
+
33
41
  export default User;
@@ -1,8 +0,0 @@
1
- import express from "express";
2
- const router = express.Router();
3
-
4
- router.get("/", (req, res) => {
5
- res.send("Hello World!")
6
- })
7
-
8
- export default router;