create-uk-node-server 1.0.11 → 1.1.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 +1 -1
- package/bin/cli.js +1 -1
- package/index.js +11 -5
- package/package.json +1 -1
- package/templates/javascript/index.js +7 -5
- package/templates/javascript/src/config/index.config.js +5 -0
- package/templates/javascript/src/middlewares/index.middleware.js +5 -0
- package/templates/javascript/src/models/index.models.js +5 -0
- package/templates/javascript/src/routes/index.routes.js +1 -1
- package/templates/typescript/package.json +2 -1
- package/templates/typescript/src/config/index.config.ts +5 -0
- package/templates/typescript/src/controllers/index.controller.ts +11 -0
- package/templates/typescript/src/index.ts +13 -19
- package/templates/typescript/src/middlewares/errorHandler.ts +9 -0
- package/templates/typescript/src/middlewares/index.middleware.ts +5 -0
- package/templates/typescript/src/models/index.models.ts +5 -0
- package/templates/typescript/src/routes/index.route.ts +4 -3
- package/templates/typescript/src/routes/user.routes.ts +11 -0
- package/templates/typescript/src/controllers/test.controller.ts +0 -0
- /package/templates/javascript/src/routes/{uesr.routes.js → user.routes.js} +0 -0
- /package/templates/typescript/src/{utils → config}/db.config.ts +0 -0
package/README.md
CHANGED
package/bin/cli.js
CHANGED
package/index.js
CHANGED
@@ -18,8 +18,14 @@ async function main() {
|
|
18
18
|
type: "input",
|
19
19
|
name: "projectName",
|
20
20
|
message: "Enter the name of your project",
|
21
|
-
default: "
|
22
|
-
}
|
21
|
+
default: ""
|
22
|
+
},
|
23
|
+
{
|
24
|
+
type: "input",
|
25
|
+
name: "description",
|
26
|
+
message: "Enter the description of your project",
|
27
|
+
default: "A new nodejs project"
|
28
|
+
},
|
23
29
|
]);
|
24
30
|
|
25
31
|
const templatePath = path.join(__dirname, "templates", answers.language.toLowerCase());
|
@@ -29,13 +35,13 @@ async function main() {
|
|
29
35
|
if (err) return console.error(err)
|
30
36
|
const pkgPath = path.join(projectPath, "package.json");
|
31
37
|
const pkg = fs.readJsonSync(pkgPath);
|
32
|
-
pkg.name = answers.projectName;
|
38
|
+
pkg.name = answers.projectName.toLowerCase() || process.cwd().replace(/\\/g, "/").split("/").pop().toLowerCase();
|
39
|
+
pkg.description = answers.description;
|
33
40
|
fs.writeJsonSync(pkgPath, pkg, { spaces: 2 });
|
34
41
|
console.log("Installing dependencies...")
|
35
42
|
execSync(`cd ${projectPath} && npm install`);
|
36
43
|
console.log('success!')
|
37
|
-
console.log(`create .env file and add DB_URL
|
38
|
-
console.log(`run npm start`)
|
44
|
+
console.log(`create .env file and add DB_URL="your-db-connection-string" && run npm start`)
|
39
45
|
})
|
40
46
|
}
|
41
47
|
|
package/package.json
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
import express from "express"
|
2
|
-
import
|
2
|
+
import dotenv from 'dotenv';
|
3
|
+
dotenv.config();
|
4
|
+
import indexConfig from "./src/config/index.config.js"
|
3
5
|
import indexRoutes from "./src/routes/index.routes.js"
|
4
|
-
import
|
6
|
+
import indexMiddleware from "./src/middlewares/index.middleware.js"
|
5
7
|
|
6
8
|
const app = express()
|
7
|
-
const PORT = 3000
|
9
|
+
const PORT = process.env.PORT || 3000;
|
8
10
|
|
9
11
|
app.use(express.json());
|
10
12
|
app.use(express.urlencoded({ extended: true }));
|
11
|
-
app.use(errorHandler);
|
13
|
+
app.use(indexMiddleware.errorHandler);
|
12
14
|
|
13
15
|
app.use("/api", indexRoutes)
|
14
16
|
|
15
|
-
connectDB()
|
17
|
+
indexConfig.connectDB()
|
16
18
|
.then(() => {
|
17
19
|
app.listen(PORT, () => {
|
18
20
|
console.log(`Server is running on port ${PORT}`)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Request, Response } from "express";
|
2
|
+
import { errorResponse, successResponse } from "../utils/general.js";
|
3
|
+
|
4
|
+
export const test = async (req: Request, res: Response) => {
|
5
|
+
try {
|
6
|
+
return res.json(successResponse("Hello from test", {}))
|
7
|
+
} catch (error) {
|
8
|
+
console.log("Error in test--------->", error)
|
9
|
+
return res.json(errorResponse("Something went wrong", error))
|
10
|
+
}
|
11
|
+
}
|
@@ -1,34 +1,28 @@
|
|
1
1
|
import express from 'express';
|
2
2
|
import cors from 'cors';
|
3
3
|
import dotenv from 'dotenv';
|
4
|
-
import
|
4
|
+
import indexConfig from './config/index.config.js';
|
5
5
|
import indexRoutes from './routes/index.route.js';
|
6
|
+
import indexMiddleware from './middlewares/index.middleware.js';
|
6
7
|
|
7
8
|
dotenv.config();
|
8
9
|
|
9
10
|
const app = express();
|
10
|
-
const PORT = process.env.
|
11
|
+
const PORT = process.env.PORT || 3000;
|
11
12
|
|
12
13
|
app.use(cors());
|
13
14
|
app.use(express.json());
|
14
15
|
app.use(express.urlencoded({ extended: true }));
|
15
|
-
|
16
|
-
app.get('/', (req, res) => {
|
17
|
-
res.json({ message: 'Welcome to TypeScript Server!' });
|
18
|
-
});
|
16
|
+
app.use(indexMiddleware.errorHandler);
|
19
17
|
|
20
18
|
app.use('/api', indexRoutes);
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
})
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
};
|
33
|
-
|
34
|
-
startServer();
|
20
|
+
indexConfig.connectDB()
|
21
|
+
.then(() => {
|
22
|
+
app.listen(PORT, () => {
|
23
|
+
console.log(`Server is running on port ${PORT}`)
|
24
|
+
})
|
25
|
+
}).catch((error) => {
|
26
|
+
console.error("Error connecting to MongoDB:", error)
|
27
|
+
process.exit(1)
|
28
|
+
})
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { Router, Request, Response } from 'express';
|
2
|
+
import { test} from "../controllers/index.controller.js"
|
3
|
+
import userRouter from "./user.routes.js"
|
2
4
|
|
3
5
|
const router = Router();
|
4
6
|
|
5
|
-
router.get('/',
|
6
|
-
|
7
|
-
});
|
7
|
+
router.get('/', test);
|
8
|
+
router.use("/users", userRouter)
|
8
9
|
|
9
10
|
export default router;
|
File without changes
|
File without changes
|
File without changes
|