4bnode 3.5.3 → 4.0.2

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