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.
- package/README.md +139 -114
- 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 +288 -155
- package/lib/env.js +18 -0
- package/lib/indexFile.js +87 -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/dev-api.js +2785 -0
- package/skeleton/index.js +10 -3
- package/skeleton/package.json +9 -5
- package/skeleton/public/fonts/NotoSans-Bold.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-Light.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-Medium.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-Regular.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-SemiBold.woff2 +0 -0
- package/skeleton/public/images/mongo.png +0 -0
- package/skeleton/public/images/mysql.png +0 -0
- package/skeleton/public/images/postgresql.png +0 -0
- package/skeleton/public/images/sqlite.png +0 -0
- package/skeleton/public/index.html +7562 -64
- 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,199 +1,224 @@
|
|
|
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
|
-
|
|
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
|
-
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
|
-
|
|
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
|
-
|
|
46
|
+
npx 4bnode add
|
|
53
47
|
```
|
|
54
48
|
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
+
### API Endpoint Creation
|
|
66
62
|
|
|
67
63
|
```sh
|
|
68
|
-
|
|
64
|
+
4bnode add api users
|
|
69
65
|
```
|
|
70
66
|
|
|
71
|
-
|
|
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
|
-
|
|
74
|
+
### Schema Management
|
|
74
75
|
|
|
75
76
|
```sh
|
|
76
|
-
|
|
77
|
+
4bnode schema # Interactive create/view/edit
|
|
78
|
+
4bnode schema user # Create or edit 'user' schema
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
Supported field types: `String`, `Number`, `Boolean`, `Date`, `Array`, `ObjectId`, `Mixed`, `Buffer`
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
Field constraints: `required`, `unique`, `default`
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
node-app add-mongo-delete
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### `node-app add-socket`
|
|
85
|
+
Presets available: `user`, `product`, `post`
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
### List Project Info
|
|
90
88
|
|
|
91
89
|
```sh
|
|
92
|
-
|
|
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
|
-
###
|
|
96
|
-
|
|
97
|
-
Add native WebSocket support to your project.
|
|
95
|
+
### Start Dev Dashboard
|
|
98
96
|
|
|
99
97
|
```sh
|
|
100
|
-
|
|
98
|
+
4bnode ui
|
|
101
99
|
```
|
|
102
100
|
|
|
103
|
-
|
|
101
|
+
Runs `npm run dev` and opens the visual dashboard. Must be run inside a 4bnode project.
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
## Visual Dashboard
|
|
106
104
|
|
|
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`
|
|
105
|
+
Access at `http://localhost:3000/_dev` when running `npm run dev`.
|
|
111
106
|
|
|
112
|
-
|
|
113
|
-
node-app add-serialport
|
|
114
|
-
```
|
|
107
|
+
### Dashboard Features
|
|
115
108
|
|
|
116
|
-
|
|
109
|
+
**Overview** - Project status, configured features, quick stats
|
|
117
110
|
|
|
118
|
-
|
|
111
|
+
**Database** - MongoDB connection setup, URI management
|
|
119
112
|
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
144
|
+
**Real-time** - Socket.IO and WebSocket configuration
|
|
129
145
|
|
|
130
|
-
|
|
131
|
-
node-app add-mongo-schema User
|
|
132
|
-
```
|
|
146
|
+
**SerialPort** - Serial port setup with path and baud rate config
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
**Environment** - View and edit `.env.development` and `.env.production`
|
|
135
149
|
|
|
136
|
-
|
|
150
|
+
## Generated Project Structure
|
|
137
151
|
|
|
138
|
-
```
|
|
139
|
-
|
|
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
|
|
143
|
-
|
|
144
|
-
### WebSocket Integration
|
|
173
|
+
## Real-time Communication
|
|
145
174
|
|
|
146
|
-
|
|
175
|
+
### Socket.IO
|
|
147
176
|
|
|
148
177
|
```sh
|
|
149
|
-
|
|
178
|
+
4bnode add socket
|
|
150
179
|
```
|
|
151
180
|
|
|
152
|
-
|
|
181
|
+
Access in routes via `req.io`:
|
|
153
182
|
|
|
154
183
|
```js
|
|
155
|
-
router.get(
|
|
156
|
-
req.
|
|
157
|
-
|
|
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
|
-
###
|
|
166
|
-
|
|
167
|
-
When you add Socket.io integration, it will automatically be added to your project.
|
|
190
|
+
### WebSocket
|
|
168
191
|
|
|
169
192
|
```sh
|
|
170
|
-
|
|
193
|
+
4bnode add websocket
|
|
171
194
|
```
|
|
172
195
|
|
|
173
|
-
|
|
196
|
+
Access in routes via `req.wss`:
|
|
174
197
|
|
|
175
198
|
```js
|
|
176
|
-
router.get(
|
|
177
|
-
req.
|
|
178
|
-
|
|
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
|
-
|
|
212
|
+
4bnode -h
|
|
213
|
+
4bnode --help
|
|
188
214
|
```
|
|
189
215
|
|
|
190
|
-
|
|
216
|
+
## License
|
|
191
217
|
|
|
192
|
-
|
|
193
|
-
node-app -h
|
|
194
|
-
node-app --help
|
|
195
|
-
```
|
|
218
|
+
Proprietary License
|
|
196
219
|
|
|
197
|
-
|
|
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
|
-
|
|
224
|
+
For licensing or commercial use: contact@4brains.in
|