@patel.ajay745/exinit 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +171 -0
  2. package/package.json +8 -2
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # exinit
2
+
3
+ Every time you start a new Express backend you end up doing the same thing. Create a folder, set up TypeScript, write the same error handler, the same async wrapper, the same response class, and then finally start working on the actual feature you wanted to build. That setup easily takes 30 minutes and it is the same 30 minutes every single time.
4
+
5
+ exinit fixes that. One command and your project is ready to go.
6
+
7
+ ## What you get
8
+
9
+ When you run exinit it asks you three questions and then creates a complete Express project for you. You choose the language (TypeScript or JavaScript), the module system if you picked JavaScript (CommonJS or ES Modules), and the package manager you want to use. After that it sets everything up and installs the dependencies automatically.
10
+
11
+ The generated project comes with four utility files that most Express apps need anyway.
12
+
13
+ **ApiError** is a custom error class. Instead of throwing generic errors you throw an ApiError with a status code and a message. Your error handler knows how to deal with it and sends a clean JSON response.
14
+
15
+ **ApiResponse** is a response wrapper. Every successful response goes through it so your API always returns data in the same shape. The client always knows what to expect.
16
+
17
+ **asyncHandler** is a wrapper for async route handlers. You wrap your async functions with it and you never have to write try catch inside a route again. Errors are automatically passed to Express.
18
+
19
+ **errorHandler** is an Express error middleware. It catches every error in your app, handles ApiError instances specially, and falls back to a generic 500 for anything unexpected.
20
+
21
+ ## Installation
22
+
23
+ You do not need to install anything globally. Just use npx.
24
+
25
+ ```bash
26
+ npx @patel.ajay745/exinit my-app
27
+ ```
28
+
29
+ If you are already inside the folder where you want your project, you can run it without a name and it will use the current folder.
30
+
31
+ ```bash
32
+ npx @patel.ajay745/exinit
33
+ ```
34
+
35
+ Both of these also work.
36
+
37
+ ```bash
38
+ npx @patel.ajay745/exinit .
39
+ cd my-project && npx @patel.ajay745/exinit
40
+ ```
41
+
42
+ ## Interactive prompts
43
+
44
+ When you run the command you will see three prompts. Use the arrow keys to move between options and press Enter to select.
45
+
46
+ ```
47
+ ? Select language: TypeScript / JavaScript
48
+ ? Choose module system: CommonJS / ES Modules (only appears for JavaScript)
49
+ ? Choose package manager: npm / bun / pnpm / yarn
50
+ ```
51
+
52
+ Package managers that are not installed on your machine will show up as greyed out and cannot be selected.
53
+
54
+ ## Project structure
55
+
56
+ After exinit finishes you will have this structure inside your project folder.
57
+
58
+ ```
59
+ my-app/
60
+ ├── src/
61
+ │ ├── controllers/
62
+ │ ├── middlewares/
63
+ │ ├── models/
64
+ │ ├── routes/
65
+ │ │ └── index.ts (sample health check route)
66
+ │ ├── services/
67
+ │ ├── config/
68
+ │ ├── dto/ (TypeScript only)
69
+ │ ├── types/ (TypeScript only)
70
+ │ ├── utils/
71
+ │ │ ├── apiError.ts
72
+ │ │ ├── apiResponse.ts
73
+ │ │ ├── asyncHandler.ts
74
+ │ │ └── errorHandler.ts
75
+ │ └── index.ts (Express app entry point)
76
+ ├── .env.example
77
+ ├── .gitignore
78
+ ├── package.json
79
+ └── tsconfig.json (TypeScript only)
80
+ ```
81
+
82
+ ## Starting your project
83
+
84
+ After the scaffold finishes, go into your project folder and start the dev server.
85
+
86
+ ```bash
87
+ cd my-app
88
+ npm run dev
89
+ ```
90
+
91
+ Once it is running, hit this endpoint to confirm everything is working.
92
+
93
+ ```
94
+ GET http://localhost:3000/api/health
95
+ ```
96
+
97
+ You should get back something like this.
98
+
99
+ ```json
100
+ {
101
+ "statusCode": 200,
102
+ "message": "Server is healthy",
103
+ "data": { "status": "ok" },
104
+ "success": true
105
+ }
106
+ ```
107
+
108
+ ## Available scripts
109
+
110
+ The generated project comes with these scripts.
111
+
112
+ **TypeScript projects**
113
+
114
+ ```bash
115
+ npm run dev # starts the dev server with hot reload
116
+ npm run build # compiles TypeScript to JavaScript in dist/
117
+ npm start # runs the compiled output
118
+ ```
119
+
120
+ **JavaScript projects**
121
+
122
+ ```bash
123
+ npm run dev # starts the dev server with hot reload via nodemon
124
+ npm start # runs the project directly with Node
125
+ ```
126
+
127
+ If you chose bun, pnpm, or yarn, replace `npm run` with your package manager. For example `pnpm dev` or `bun dev`.
128
+
129
+ ## Using the utilities
130
+
131
+ Here is a quick example of how the utilities work together in a real route.
132
+
133
+ ```typescript
134
+ import { Router } from "express";
135
+ import { asyncHandler } from "@/utils/asyncHandler";
136
+ import { ApiResponse } from "@/utils/apiResponse";
137
+ import { ApiError } from "@/utils/apiError";
138
+
139
+ const router = Router();
140
+
141
+ router.get("/user/:id", asyncHandler(async (req, res) => {
142
+ const user = await getUserById(req.params.id);
143
+
144
+ if (!user) {
145
+ throw new ApiError(404, "User not found");
146
+ }
147
+
148
+ res.status(200).json(new ApiResponse(200, "User fetched successfully", user));
149
+ }));
150
+ ```
151
+
152
+ If `getUserById` throws or `user` is not found, the error flows to the errorHandler automatically. No try catch needed.
153
+
154
+ ## Environment variables
155
+
156
+ Copy the example file and fill in your values.
157
+
158
+ ```bash
159
+ cp .env.example .env
160
+ ```
161
+
162
+ The default variables are:
163
+
164
+ ```
165
+ PORT=3000
166
+ NODE_ENV=development
167
+ ```
168
+
169
+ ## Requirements
170
+
171
+ Node.js version 18 or higher is required.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patel.ajay745/exinit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Scaffold a production-ready Express project in seconds",
5
5
  "bin": {
6
6
  "exinit": "./dist/cli.js"
@@ -18,7 +18,13 @@
18
18
  "engines": {
19
19
  "node": ">=18.0.0"
20
20
  },
21
- "keywords": ["express", "typescript", "boilerplate", "scaffold", "starter"],
21
+ "keywords": [
22
+ "express",
23
+ "typescript",
24
+ "boilerplate",
25
+ "scaffold",
26
+ "starter"
27
+ ],
22
28
  "license": "MIT",
23
29
  "devDependencies": {
24
30
  "typescript": "^5.4.5",