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.
@@ -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,4 @@
1
+ export const config = {
2
+ PORT: process.env.PORT || 5000,
3
+ env: process.env.NODE_ENV || 'development',
4
+ };
@@ -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,4 @@
1
+ [
2
+ { "id": 1, "name": "John Doe", "email": "john@example.com" },
3
+ { "id": 2, "name": "Jane Smith", "email": "jane@example.com" }
4
+ ]
@@ -0,0 +1,8 @@
1
+ import express from "express"
2
+ const router = express.Router()
3
+
4
+ router.get("/test", (req, res) => {
5
+ res.json({ message: "API is working" })
6
+ })
7
+
8
+ export default router
@@ -0,0 +1,9 @@
1
+ import { Router } from 'express';
2
+ import { getAllUsers, getUserById } from '../controllers/userController';
3
+
4
+ const router = Router();
5
+
6
+ router.get('/', getAllUsers);
7
+ router.get('/:id', getUserById);
8
+
9
+ export default router;
@@ -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
+ }