create-ts-express-app 1.0.0
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 +97 -0
- package/bin/cli.js +47 -0
- package/package.json +46 -0
- package/template/.env.example +1 -0
- package/template/.eslintrc.js +12 -0
- package/template/.prettierrc +6 -0
- package/template/Readme.md +97 -0
- package/template/package-lock.json +3002 -0
- package/template/package.json +44 -0
- package/template/src/config/config.ts +4 -0
- package/template/src/controllers/userController.ts +20 -0
- package/template/src/index.ts +27 -0
- package/template/src/middleware/errorHandler.ts +14 -0
- package/template/src/models/users.json +4 -0
- package/template/src/routes/api.ts +8 -0
- package/template/src/routes/userRoutes.ts +9 -0
- package/template/tsconfig.json +16 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
"name": "create-ts-express-kit",
|
3
|
+
"version": "1.1.0",
|
4
|
+
"main": "index.js",
|
5
|
+
"bin": {
|
6
|
+
"create-ts-express-kit": "./create.js"
|
7
|
+
},
|
8
|
+
"scripts": {
|
9
|
+
"build": "tsc",
|
10
|
+
"start": "node dist/index.js",
|
11
|
+
"dev": "nodemon --exec ts-node src/index.ts",
|
12
|
+
"dev:watch": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts"
|
13
|
+
},
|
14
|
+
"keywords": [],
|
15
|
+
"author": "Harsh Pal",
|
16
|
+
"license": "MIT",
|
17
|
+
"description": "A simple backend starter for ts",
|
18
|
+
"devDependencies": {
|
19
|
+
"@types/node": "^22.14.1",
|
20
|
+
"@typescript-eslint/eslint-plugin": "^8.30.1",
|
21
|
+
"@typescript-eslint/parser": "^8.30.1",
|
22
|
+
"eslint": "^9.24.0",
|
23
|
+
"eslint-config-prettier": "^10.1.2",
|
24
|
+
"eslint-plugin-prettier": "^5.2.6",
|
25
|
+
"nodemon": "^3.1.9",
|
26
|
+
"prettier": "^3.5.3",
|
27
|
+
"ts-node": "^10.9.2",
|
28
|
+
"typescript": "^5.8.3"
|
29
|
+
},
|
30
|
+
"dependencies": {
|
31
|
+
"@types/express": "^5.0.1",
|
32
|
+
"dotenv": "^16.5.0",
|
33
|
+
"express": "^5.1.0",
|
34
|
+
"ncp": "^2.0.0"
|
35
|
+
},
|
36
|
+
"repository": {
|
37
|
+
"type": "git",
|
38
|
+
"url": "https://github.com/harsh-dev0/ts-express.git"
|
39
|
+
},
|
40
|
+
"bugs": {
|
41
|
+
"url": "https://github.com/harsh-dev0/ts-express/issues"
|
42
|
+
},
|
43
|
+
"homepage": "https://github.com/harsh-dev0/ts-express#readme"
|
44
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Request, Response } from 'express';
|
2
|
+
import users from '../models/users.json';
|
3
|
+
|
4
|
+
// Get all users
|
5
|
+
export const getAllUsers = (req: Request, res: Response) => {
|
6
|
+
res.json(users);
|
7
|
+
};
|
8
|
+
|
9
|
+
// Get user by ID
|
10
|
+
export const getUserById = (req: Request, res: Response): void => {
|
11
|
+
const id = parseInt(req.params.id);
|
12
|
+
const user = users.find((u) => u.id === id);
|
13
|
+
|
14
|
+
if (!user) {
|
15
|
+
res.status(404).json({ message: 'User not found' });
|
16
|
+
return; // Ensure the function exits after sending a response
|
17
|
+
}
|
18
|
+
|
19
|
+
res.json(user);
|
20
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import express from 'express';
|
2
|
+
import dotenv from 'dotenv';
|
3
|
+
dotenv.config();
|
4
|
+
import { errorHandler } from './middleware/errorHandler';
|
5
|
+
import apiRoutes from './routes/api';
|
6
|
+
import { config } from './config/config';
|
7
|
+
import userRoutes from './routes/userRoutes';
|
8
|
+
|
9
|
+
// Load environment variables
|
10
|
+
const app = express();
|
11
|
+
const PORT = config.PORT;
|
12
|
+
// Middleware
|
13
|
+
app.use(express.json());
|
14
|
+
app.use(express.urlencoded({ extended: true }));
|
15
|
+
|
16
|
+
// Routes
|
17
|
+
app.use('/api', apiRoutes);
|
18
|
+
app.use('/api/users', userRoutes);
|
19
|
+
app.get('/', (req, res) => {
|
20
|
+
res.send('TypeScript Node.js Backend is running!');
|
21
|
+
});
|
22
|
+
|
23
|
+
app.use(errorHandler);
|
24
|
+
// Start server
|
25
|
+
app.listen(PORT, () => {
|
26
|
+
console.log(`Server running on port http://localhost:${PORT}`);
|
27
|
+
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Request, Response, NextFunction } from "express"
|
2
|
+
|
3
|
+
export const errorHandler = (
|
4
|
+
err: Error,
|
5
|
+
req: Request,
|
6
|
+
res: Response,
|
7
|
+
next: NextFunction
|
8
|
+
) => {
|
9
|
+
console.error(err.stack)
|
10
|
+
res.status(500).json({
|
11
|
+
success: false,
|
12
|
+
error: "Server Error",
|
13
|
+
})
|
14
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ES2020",
|
4
|
+
"module": "NodeNext",
|
5
|
+
"moduleResolution": "NodeNext",
|
6
|
+
"esModuleInterop": true,
|
7
|
+
"strict": true,
|
8
|
+
"outDir": "./dist",
|
9
|
+
"rootDir": "./src",
|
10
|
+
"skipLibCheck": true,
|
11
|
+
"resolveJsonModule": true,
|
12
|
+
"forceConsistentCasingInFileNames": true
|
13
|
+
},
|
14
|
+
"include": ["src/**/*"],
|
15
|
+
"exclude": ["node_modules"]
|
16
|
+
}
|