4bnode 3.5.2 → 4.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.
Files changed (43) hide show
  1. package/README.md +139 -114
  2. package/add-api.js +288 -156
  3. package/add-crud.js +226 -0
  4. package/add-login.js +152 -319
  5. package/add-mongo-delete.js +67 -138
  6. package/add-mongo-insert.js +87 -204
  7. package/add-mongo-read.js +100 -216
  8. package/add-mongo-schema.js +431 -199
  9. package/add-mongo-update.js +89 -202
  10. package/add-mongo.js +125 -218
  11. package/add-serialport.js +53 -98
  12. package/add-socket.js +43 -66
  13. package/add-websocket.js +68 -140
  14. package/index.js +288 -155
  15. package/lib/env.js +18 -0
  16. package/lib/indexFile.js +87 -0
  17. package/lib/names.js +21 -0
  18. package/lib/project.js +122 -0
  19. package/lib/routeFile.js +56 -0
  20. package/lib/ui.js +161 -0
  21. package/package.json +9 -16
  22. package/skeleton/dev-api.js +2785 -0
  23. package/skeleton/index.js +10 -3
  24. package/skeleton/package.json +9 -5
  25. package/skeleton/public/fonts/NotoSans-Bold.woff2 +0 -0
  26. package/skeleton/public/fonts/NotoSans-Light.woff2 +0 -0
  27. package/skeleton/public/fonts/NotoSans-Medium.woff2 +0 -0
  28. package/skeleton/public/fonts/NotoSans-Regular.woff2 +0 -0
  29. package/skeleton/public/fonts/NotoSans-SemiBold.woff2 +0 -0
  30. package/skeleton/public/images/mongo.png +0 -0
  31. package/skeleton/public/images/mysql.png +0 -0
  32. package/skeleton/public/images/postgresql.png +0 -0
  33. package/skeleton/public/images/sqlite.png +0 -0
  34. package/skeleton/public/index.html +7562 -64
  35. package/README_4bnode.md +0 -197
  36. package/src/auth/passport.js +0 -21
  37. package/src/db.js +0 -13
  38. package/test-server/.env.development +0 -1
  39. package/test-server/.env.production +0 -1
  40. package/test-server/index.js +0 -82
  41. package/test-server/package-lock.json +0 -1267
  42. package/test-server/package.json +0 -20
  43. package/test-server/public/index.html +0 -90
package/README.md CHANGED
@@ -1,199 +1,224 @@
1
- # 4Brains Node Generator
1
+ # 4bnode
2
2
 
3
- A comprehensive CLI tool to streamline the generation and management of Node.js applications by 4Brains Technologies.
4
-
5
- ## Installation
6
-
7
- To install the 4Brains Node Generator globally, use the following command:
8
-
9
- ```sh
10
- npm install -g 4brains-node-generator
3
+ ```
4
+ ██╗ ██╗██████╗ ███╗ ██╗ ██████╗ ██████╗ ███████╗
5
+ ██║ ██║██╔══██╗████╗ ██║██╔═══██╗██╔══██╗██╔════╝
6
+ ███████║██████╔╝██╔██╗ ██║██║ ██║██║ ██║█████╗
7
+ ╚════██║██╔══██╗██║╚██╗██║██║ ██║██║ ██║██╔══╝
8
+ ██║██████╔╝██║ ╚████║╚██████╔╝██████╔╝███████╗
9
+ ╚═╝╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝
11
10
  ```
12
11
 
13
- ## Available Commands
12
+ A professional CLI tool and visual dashboard to generate, manage, and test Node.js/Express applications.
14
13
 
15
- ### `node-app init <projectName>`
14
+ Built by [4Brains Technologies](https://4brains.in).
16
15
 
17
- Initialize a new Node.js project with the specified name.
16
+ ## Quick Start
18
17
 
19
18
  ```sh
20
- node-app init my-project
19
+ npx 4bnode init my-app
20
+ cd my-app
21
+ npm run dev
21
22
  ```
22
23
 
23
- ### `node-app add-api <endpointName>`
24
+ Your app runs at `http://localhost:3000` with a built-in visual dashboard at `http://localhost:3000/_dev`.
24
25
 
25
- Add a new API endpoint to your project.
26
+ ## CLI Commands
26
27
 
27
- ```sh
28
- node-app add-api users
29
- ```
30
-
31
- ### `node-app add-mongo`
32
-
33
- Integrate MongoDB into your project. This command sets up the necessary MongoDB configuration.
28
+ ### Create a Project
34
29
 
35
30
  ```sh
36
- node-app add-mongo
31
+ npx 4bnode init <name>
37
32
  ```
38
33
 
39
- ### `node-app add-mongo-schema <schemaName>`
40
-
41
- Create a new MongoDB schema. You will be prompted to enter field details for the schema.
42
-
43
- ```sh
44
- node-app add-mongo-schema User
45
- ```
34
+ Scaffolds a new Express project with:
35
+ - ES Module syntax
36
+ - Environment config (`.env.development`, `.env.production`)
37
+ - CORS, JSON body parser (50MB limit)
38
+ - Static file serving from `public/`
39
+ - Built-in dev dashboard at `/_dev`
46
40
 
47
- ### `node-app add-login`
41
+ ### Add Features
48
42
 
49
- Add a login template to an existing route in your project. You will be prompted to select a route and a model, and then enter the login fields.
43
+ Use the interactive menu:
50
44
 
51
45
  ```sh
52
- node-app add-login
46
+ npx 4bnode add
53
47
  ```
54
48
 
55
- ### `node-app add-mongo-insert`
56
-
57
- Add a template for inserting data into a MongoDB collection. This command allows you to easily create routes for data insertion.
58
-
59
- ```sh
60
- node-app add-mongo-insert
61
- ```
49
+ Or add directly:
62
50
 
63
- ### `node-app add-mongo-update`
51
+ | Command | Description |
52
+ |---------|-------------|
53
+ | `4bnode add api <name>` | Create a new API endpoint |
54
+ | `4bnode add mongo` | Configure MongoDB connection |
55
+ | `4bnode add crud` | Add CRUD operations to a route |
56
+ | `4bnode add login` | Add JWT authentication & login |
57
+ | `4bnode add socket` | Integrate Socket.IO |
58
+ | `4bnode add websocket` | Add native WebSocket support |
59
+ | `4bnode add serialport` | Serial port communication |
64
60
 
65
- Add a template for updating data in a MongoDB collection. This facilitates creating routes for updating documents.
61
+ ### API Endpoint Creation
66
62
 
67
63
  ```sh
68
- node-app add-mongo-update
64
+ 4bnode add api users
69
65
  ```
70
66
 
71
- ### `node-app add-mongo-read`
67
+ When creating an API endpoint:
68
+ - Select HTTP method (GET, POST, PUT, DELETE, PATCH)
69
+ - Choose fields from existing model (if available)
70
+ - Add custom fields received from client
71
+ - File fields auto-configure `multer` for multipart uploads
72
+ - All routes use `/api/` prefix
72
73
 
73
- Add a template for reading data from a MongoDB collection, helping you to quickly set up read operations.
74
+ ### Schema Management
74
75
 
75
76
  ```sh
76
- node-app add-mongo-read
77
+ 4bnode schema # Interactive create/view/edit
78
+ 4bnode schema user # Create or edit 'user' schema
77
79
  ```
78
80
 
79
- ### `node-app add-mongo-delete`
81
+ Supported field types: `String`, `Number`, `Boolean`, `Date`, `Array`, `ObjectId`, `Mixed`, `Buffer`
80
82
 
81
- Add a template for deleting data from a MongoDB collection, making it easy to handle deletion operations.
83
+ Field constraints: `required`, `unique`, `default`
82
84
 
83
- ```sh
84
- node-app add-mongo-delete
85
- ```
86
-
87
- ### `node-app add-socket`
85
+ Presets available: `user`, `product`, `post`
88
86
 
89
- Integrate Socket.io into your project for real-time communication capabilities.
87
+ ### List Project Info
90
88
 
91
89
  ```sh
92
- node-app add-socket
90
+ 4bnode list # Show all models, routes & config
91
+ 4bnode list models # List models only
92
+ 4bnode list routes # List routes only
93
93
  ```
94
94
 
95
- ### `node-app add-websocket`
96
-
97
- Add native WebSocket support to your project.
95
+ ### Start Dev Dashboard
98
96
 
99
97
  ```sh
100
- node-app add-websocket
98
+ 4bnode ui
101
99
  ```
102
100
 
103
- ### `node-app add-serialport`
101
+ Runs `npm run dev` and opens the visual dashboard. Must be run inside a 4bnode project.
104
102
 
105
- Integrate SerialPort functionality into your project. This command does the following:
103
+ ## Visual Dashboard
106
104
 
107
- - Prompts for Serial Port path and baud rate
108
- - Automatically updates `.env.development` and `.env.production` with `SERIALPORT_PATH` and `BAUDRATE`
109
- - Adds SerialPort and Readline parser setup to your `index.js`
110
- - Installs required dependencies: `serialport` and `@serialport/parser-readline`
105
+ Access at `http://localhost:3000/_dev` when running `npm run dev`.
111
106
 
112
- ```sh
113
- node-app add-serialport
114
- ```
107
+ ### Dashboard Features
115
108
 
116
- Once added, your project will automatically initialize the serial port with the specified configuration and log incoming data.
109
+ **Overview** - Project status, configured features, quick stats
117
110
 
118
- Example incoming data log:
111
+ **Database** - MongoDB connection setup, URI management
119
112
 
120
- ```sh
121
- Received data: <data from serial device>
122
- ```
113
+ **Schemas** - Create, view, edit MongoDB schemas with field management. Add/remove fields, toggle required/unique, set defaults.
123
114
 
124
- ## Examples
115
+ **API Routes** - Full route management:
116
+ - Create new routes (Methods, CRUD, Login, Register)
117
+ - Add methods to existing routes with field selection
118
+ - Select fields from models or add custom fields
119
+ - File upload fields auto-configure multer
120
+ - View route source code, edit inline
121
+ - Share endpoint docs with frontend team (Markdown format)
122
+ - Delete routes (removes file + index.js registration)
125
123
 
126
- ### Adding MongoDB Schema
124
+ **API Tester** - Built-in Postman-like API testing tool:
125
+ - REST API, Socket.IO, and WebSocket testing
126
+ - **Body types**: JSON, Form Data, URL Encoded, Raw, Binary
127
+ - **File uploads**: Choose file, send as File or Base64
128
+ - **Auto-detect fields**: Matches URL to route and pre-fills body/form fields from route code
129
+ - **Path variables**: Auto-detects `:id` params, shows editable fields
130
+ - **Query params**: Key-value editor, auto-fills from `req.query`
131
+ - **Headers**: Key-value editor with quick presets (Bearer Auth, JSON, Form Data, URL Encoded, Accept)
132
+ - **Response viewer**: Body + Headers tabs, copy response, save responses
133
+ - **Collection management**: Save requests, organize with responses, delete with confirmation
134
+ - **Share collection**: Generate shareable API documentation page with:
135
+ - Endpoint details, headers, body fields
136
+ - Code examples (cURL, Fetch, Axios) with copy button
137
+ - Form data / file upload code generation
138
+ - Saved response examples
139
+ - Search/filter endpoints
140
+ - Persistent URL (updates on re-share)
141
+ - **Import from routes**: One-click import endpoints from your project routes
142
+ - All data persisted in `.4bnode/` JSON files (not localStorage)
127
143
 
128
- When you run the command to add a MongoDB schema, you will be prompted to enter the field details.
144
+ **Real-time** - Socket.IO and WebSocket configuration
129
145
 
130
- ```sh
131
- node-app add-mongo-schema User
132
- ```
146
+ **SerialPort** - Serial port setup with path and baud rate config
133
147
 
134
- ### Adding a Login Template
148
+ **Environment** - View and edit `.env.development` and `.env.production`
135
149
 
136
- When you run the command to add a login template, you will be prompted to select a route and a model, and then enter the login fields.
150
+ ## Generated Project Structure
137
151
 
138
- ```sh
139
- node-app add-login
152
+ ```
153
+ my-app/
154
+ ├── index.js # Express app entry point
155
+ ├── dev-api.js # Dev dashboard API (auto-included)
156
+ ├── package.json
157
+ ├── .env.development # Dev environment variables
158
+ ├── .env.production # Production environment variables
159
+ ├── .4bnode/ # Dashboard data (tester, shared collections)
160
+ ├── public/ # Static files
161
+ │ ├── index.html # Dashboard UI
162
+ │ ├── fonts/
163
+ │ └── images/
164
+ ├── uploads/ # File uploads (when using multer)
165
+ └── src/
166
+ ├── db.js # MongoDB connection (after `add mongo`)
167
+ ├── models/ # Mongoose schemas
168
+ ├── routes/ # API route files
169
+ └── middleware/
170
+ └── auth.js # JWT auth middleware (after `add login`)
140
171
  ```
141
172
 
142
- ## Real-time Communication Integration
143
-
144
- ### WebSocket Integration
173
+ ## Real-time Communication
145
174
 
146
- When you add WebSocket integration, it will automatically be added to your project.
175
+ ### Socket.IO
147
176
 
148
177
  ```sh
149
- node-app add-websocket
178
+ 4bnode add socket
150
179
  ```
151
180
 
152
- To use `req.wss` in your route endpoints, you can access the WebSocket server as follows:
181
+ Access in routes via `req.io`:
153
182
 
154
183
  ```js
155
- router.get("/some-endpoint", (req, res) => {
156
- req.wss.clients.forEach((client) => {
157
- if (client.readyState === WebSocket.OPEN) {
158
- client.send("Hello, client!");
159
- }
160
- });
161
- res.send("Message sent to all WebSocket clients.");
184
+ router.get('/notify', (req, res) => {
185
+ req.io.emit('message', 'Hello from server');
186
+ res.json({ sent: true });
162
187
  });
163
188
  ```
164
189
 
165
- ### Socket.io Integration
166
-
167
- When you add Socket.io integration, it will automatically be added to your project.
190
+ ### WebSocket
168
191
 
169
192
  ```sh
170
- node-app add-socket
193
+ 4bnode add websocket
171
194
  ```
172
195
 
173
- To use `req.io` in your route endpoints, you can access the Socket.io server as follows:
196
+ Access in routes via `req.wss`:
174
197
 
175
198
  ```js
176
- router.get("/some-endpoint", (req, res) => {
177
- req.io.emit("message", "Hello, Socket.io clients!");
178
- res.send("Message sent to all Socket.io clients.");
199
+ router.get('/broadcast', (req, res) => {
200
+ req.wss.clients.forEach(client => {
201
+ if (client.readyState === WebSocket.OPEN) {
202
+ client.send('Hello from server');
203
+ }
204
+ });
205
+ res.json({ sent: true });
179
206
  });
180
207
  ```
181
208
 
182
209
  ## Help
183
210
 
184
- If you enter an invalid command, you will see the following message:
185
-
186
211
  ```sh
187
- Unknown command. Use -h or --help for help.
212
+ 4bnode -h
213
+ 4bnode --help
188
214
  ```
189
215
 
190
- You can also use `-h` or `--help` to get help information.
216
+ ## License
191
217
 
192
- ```sh
193
- node-app -h
194
- node-app --help
195
- ```
218
+ Proprietary License
196
219
 
197
- ## License
220
+ (c) 2025 4Brains Technologies. All rights reserved.
221
+
222
+ Unauthorized copying, distribution, modification, or use of this code is strictly prohibited.
198
223
 
199
- This project is licensed under the ISC License.
224
+ For licensing or commercial use: contact@4brains.in