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.
- package/README.md +144 -109
- package/add-api.js +288 -156
- package/add-crud.js +226 -0
- package/add-login.js +152 -319
- package/add-mongo-delete.js +67 -138
- package/add-mongo-insert.js +87 -204
- package/add-mongo-read.js +100 -216
- package/add-mongo-schema.js +431 -199
- package/add-mongo-update.js +89 -202
- package/add-mongo.js +125 -218
- package/add-serialport.js +53 -98
- package/add-socket.js +43 -66
- package/add-websocket.js +68 -140
- package/index.js +341 -156
- package/lib/env.js +18 -0
- package/lib/indexFile.js +134 -0
- package/lib/names.js +21 -0
- package/lib/project.js +122 -0
- package/lib/routeFile.js +56 -0
- package/lib/ui.js +161 -0
- package/package.json +9 -16
- package/skeleton/.4bnode/assets/fonts/NotoSans-Bold.woff2 +0 -0
- package/skeleton/.4bnode/assets/fonts/NotoSans-Light.woff2 +0 -0
- package/skeleton/.4bnode/assets/fonts/NotoSans-Medium.woff2 +0 -0
- package/skeleton/.4bnode/assets/fonts/NotoSans-Regular.woff2 +0 -0
- package/skeleton/.4bnode/assets/fonts/NotoSans-SemiBold.woff2 +0 -0
- package/skeleton/.4bnode/assets/images/mongo.png +0 -0
- package/skeleton/.4bnode/assets/images/mysql.png +0 -0
- package/skeleton/.4bnode/assets/images/postgresql.png +0 -0
- package/skeleton/.4bnode/assets/images/sqlite.png +0 -0
- package/skeleton/.4bnode/assets/js/App.js +115 -0
- package/skeleton/.4bnode/assets/js/Root.js +44 -0
- package/skeleton/.4bnode/assets/js/components/Modal.js +52 -0
- package/skeleton/.4bnode/assets/js/components/Sidebar.js +68 -0
- package/skeleton/.4bnode/assets/js/components/ToastContainer.js +15 -0
- package/skeleton/.4bnode/assets/js/context.js +7 -0
- package/skeleton/.4bnode/assets/js/lib.js +83 -0
- package/skeleton/.4bnode/assets/js/main.js +5 -0
- package/skeleton/.4bnode/assets/js/pages/ApiTesterPage.js +1594 -0
- package/skeleton/.4bnode/assets/js/pages/DashboardPage.js +435 -0
- package/skeleton/.4bnode/assets/js/pages/DatabasePage.js +461 -0
- package/skeleton/.4bnode/assets/js/pages/EnvironmentPage.js +141 -0
- package/skeleton/.4bnode/assets/js/pages/RealtimePage.js +186 -0
- package/skeleton/.4bnode/assets/js/pages/RoutesPage.js +1656 -0
- package/skeleton/.4bnode/assets/js/pages/SchemasPage.js +901 -0
- package/skeleton/.4bnode/assets/js/pages/SerialPortPage.js +170 -0
- package/skeleton/.4bnode/assets/js/screens/PasskeyScreen.js +105 -0
- package/skeleton/.4bnode/assets/js/screens/SplashScreen.js +66 -0
- package/skeleton/.4bnode/dev-api.js +2930 -0
- package/skeleton/.4bnode/ui.html +1556 -0
- package/skeleton/index.js +70 -17
- package/skeleton/package.json +9 -5
- package/skeleton/public/index.html +288 -86
- package/README_4bnode.md +0 -197
- package/src/auth/passport.js +0 -21
- package/src/db.js +0 -13
- package/test-server/.env.development +0 -1
- package/test-server/.env.production +0 -1
- package/test-server/index.js +0 -82
- package/test-server/package-lock.json +0 -1267
- package/test-server/package.json +0 -20
- package/test-server/public/index.html +0 -90
package/README.md
CHANGED
|
@@ -1,194 +1,223 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 4bnode
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
npm install -g 4brains-node-generator
|
|
3
|
+
```
|
|
4
|
+
██╗ ██╗██████╗ ███╗ ██╗ ██████╗ ██████╗ ███████╗
|
|
5
|
+
██║ ██║██╔══██╗████╗ ██║██╔═══██╗██╔══██╗██╔════╝
|
|
6
|
+
███████║██████╔╝██╔██╗ ██║██║ ██║██║ ██║█████╗
|
|
7
|
+
╚════██║██╔══██╗██║╚██╗██║██║ ██║██║ ██║██╔══╝
|
|
8
|
+
██║██████╔╝██║ ╚████║╚██████╔╝██████╔╝███████╗
|
|
9
|
+
╚═╝╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝
|
|
11
10
|
```
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
A professional CLI tool and visual dashboard to generate, manage, and test Node.js/Express applications.
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
Built by [4Brains Technologies](https://4brains.in).
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
## Quick Start
|
|
18
17
|
|
|
19
18
|
```sh
|
|
20
|
-
4bnode init my-
|
|
19
|
+
npx 4bnode init my-app
|
|
20
|
+
cd my-app
|
|
21
|
+
npm run dev
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
Your app runs at `http://localhost:3000` with a built-in visual dashboard at `http://localhost:3000/_dev`.
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
## CLI Commands
|
|
26
27
|
|
|
27
|
-
|
|
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
|
|
31
|
+
npx 4bnode init <name>
|
|
37
32
|
```
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
###
|
|
41
|
+
### Add Features
|
|
48
42
|
|
|
49
|
-
|
|
43
|
+
Use the interactive menu:
|
|
50
44
|
|
|
51
45
|
```sh
|
|
52
|
-
4bnode add
|
|
46
|
+
npx 4bnode add
|
|
53
47
|
```
|
|
54
48
|
|
|
55
|
-
|
|
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
|
-
|
|
61
|
+
### API Endpoint Creation
|
|
58
62
|
|
|
59
63
|
```sh
|
|
60
|
-
4bnode add
|
|
64
|
+
4bnode add api users
|
|
61
65
|
```
|
|
62
66
|
|
|
63
|
-
|
|
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
|
-
|
|
74
|
+
### Schema Management
|
|
66
75
|
|
|
67
76
|
```sh
|
|
68
|
-
4bnode
|
|
77
|
+
4bnode schema # Interactive create/view/edit
|
|
78
|
+
4bnode schema user # Create or edit 'user' schema
|
|
69
79
|
```
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
Supported field types: `String`, `Number`, `Boolean`, `Date`, `Array`, `ObjectId`, `Mixed`, `Buffer`
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```sh
|
|
76
|
-
4bnode add-mongo-read
|
|
77
|
-
```
|
|
83
|
+
Field constraints: `required`, `unique`, `default`
|
|
78
84
|
|
|
79
|
-
|
|
85
|
+
Presets available: `user`, `product`, `post`
|
|
80
86
|
|
|
81
|
-
|
|
87
|
+
### List Project Info
|
|
82
88
|
|
|
83
89
|
```sh
|
|
84
|
-
4bnode
|
|
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
|
-
###
|
|
95
|
+
### Dashboard Passkey
|
|
88
96
|
|
|
89
|
-
|
|
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
|
|
102
|
+
4bnode passkey
|
|
93
103
|
```
|
|
94
104
|
|
|
95
|
-
###
|
|
96
|
-
|
|
97
|
-
Add native WebSocket support to your project.
|
|
105
|
+
### Start Dev Dashboard
|
|
98
106
|
|
|
99
107
|
```sh
|
|
100
|
-
4bnode
|
|
108
|
+
4bnode ui
|
|
101
109
|
```
|
|
102
110
|
|
|
103
|
-
|
|
111
|
+
Runs `npm run dev` and opens the visual dashboard. Must be run inside a 4bnode project.
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
## Visual Dashboard
|
|
106
114
|
|
|
107
|
-
|
|
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
|
-
|
|
113
|
-
4bnode add-serialport
|
|
114
|
-
```
|
|
117
|
+
### Dashboard Features
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
**Overview** - Project status, configured features, quick stats
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
**Database** - MongoDB connection setup, URI management
|
|
119
122
|
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
154
|
+
**Real-time** - Socket.IO and WebSocket configuration
|
|
129
155
|
|
|
130
|
-
|
|
131
|
-
4bnode add-mongo-schema User
|
|
132
|
-
```
|
|
156
|
+
**SerialPort** - Serial port setup with path and baud rate config
|
|
133
157
|
|
|
134
|
-
|
|
158
|
+
**Environment** - View and edit `.env.development` and `.env.production`
|
|
135
159
|
|
|
136
|
-
|
|
160
|
+
## Generated Project Structure
|
|
137
161
|
|
|
138
|
-
```
|
|
139
|
-
|
|
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
|
|
143
|
-
|
|
144
|
-
### WebSocket Integration
|
|
183
|
+
## Real-time Communication
|
|
145
184
|
|
|
146
|
-
|
|
185
|
+
### Socket.IO
|
|
147
186
|
|
|
148
187
|
```sh
|
|
149
|
-
4bnode add
|
|
188
|
+
4bnode add socket
|
|
150
189
|
```
|
|
151
190
|
|
|
152
|
-
|
|
191
|
+
Access in routes via `req.io`:
|
|
153
192
|
|
|
154
193
|
```js
|
|
155
|
-
router.get(
|
|
156
|
-
req.
|
|
157
|
-
|
|
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
|
-
###
|
|
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
|
|
203
|
+
4bnode add websocket
|
|
171
204
|
```
|
|
172
205
|
|
|
173
|
-
|
|
206
|
+
Access in routes via `req.wss`:
|
|
174
207
|
|
|
175
208
|
```js
|
|
176
|
-
router.get(
|
|
177
|
-
req.
|
|
178
|
-
|
|
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
|
-
|
|
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
|