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/skeleton/index.js CHANGED
@@ -1,26 +1,36 @@
1
1
  import express from "express";
2
2
  import dotenv from "dotenv";
3
- import bodyParser from "body-parser";
4
3
  import path from "path";
4
+ import fs from "fs";
5
5
  import cors from "cors";
6
6
  import os from "os";
7
+ import { createInterface } from "readline";
7
8
 
9
+ // ── Environment ─────────────────────────────────────
8
10
  const env = process.env.NODE_ENV || "development";
9
11
  dotenv.config({ path: `.env.${env}` });
10
12
 
11
13
  const app = express();
12
14
  const port = process.env.PORT || 3000;
15
+ const __dirname = path.resolve();
13
16
 
14
- // Middleware
15
- app.use(bodyParser.json({ limit: "50mb" }));
16
- app.use(bodyParser.urlencoded({ extended: true, limit: "50mb" }));
17
+ // ── Middleware ───────────────────────────────────────
18
+ app.use(express.json({ limit: "50mb" }));
19
+ app.use(express.urlencoded({ extended: true, limit: "50mb" }));
17
20
  app.use(cors({ origin: "*" }));
18
21
 
19
- // Serve static files from the public directory
20
- const __dirname = path.resolve();
22
+ // ── Dev Dashboard (development only) ────────────────
23
+ if (env === "development") {
24
+ try {
25
+ const devApi = await import("./.4bnode/dev-api.js");
26
+ app.use("/_dev", devApi.default);
27
+ } catch {}
28
+ }
29
+
30
+ // ── Static Files ────────────────────────────────────
21
31
  app.use(express.static(path.join(__dirname, "public")));
22
32
 
23
- // Get local network IP address
33
+ // ── Helpers ─────────────────────────────────────────
24
34
  function getLocalNetworkIp() {
25
35
  const interfaces = os.networkInterfaces();
26
36
  for (const name of Object.keys(interfaces)) {
@@ -33,13 +43,56 @@ function getLocalNetworkIp() {
33
43
  return null;
34
44
  }
35
45
 
36
- // Start server
37
- app.listen(port, () => {
38
- const localIp = getLocalNetworkIp();
39
- console.log(`App is running on http://localhost:${port}`);
40
- if (localIp) {
41
- console.log(
42
- `App is also accessible on your local network at http://${localIp}:${port}`
43
- );
44
- }
45
- });
46
+ function updateEnvPort(newPort) {
47
+ const envFile = `.env.${env}`;
48
+ try {
49
+ if (fs.existsSync(envFile)) {
50
+ let content = fs.readFileSync(envFile, "utf8");
51
+ if (content.match(/^PORT=.*/m)) {
52
+ content = content.replace(/^PORT=.*/m, `PORT=${newPort}`);
53
+ } else {
54
+ content += `\nPORT=${newPort}`;
55
+ }
56
+ fs.writeFileSync(envFile, content, "utf8");
57
+ }
58
+ } catch {}
59
+ }
60
+
61
+ function askPort(busyPort) {
62
+ return new Promise((resolve) => {
63
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
64
+ console.log(`\nPort ${busyPort} is already in use.`);
65
+ rl.question(`Press Enter to use ${busyPort + 1}, or type a port number: `, (answer) => {
66
+ rl.close();
67
+ const custom = parseInt(answer.trim(), 10);
68
+ resolve(custom && custom > 0 ? custom : busyPort + 1);
69
+ });
70
+ });
71
+ }
72
+
73
+ // ── Start Server ────────────────────────────────────
74
+ async function startServer(tryPort) {
75
+ const listener = app.listen(tryPort);
76
+ listener.on("listening", () => {
77
+ const localIp = getLocalNetworkIp();
78
+ console.log(`App is running on http://localhost:${tryPort}`);
79
+ if (localIp) {
80
+ console.log(`App is also accessible on your local network at http://${localIp}:${tryPort}`);
81
+ }
82
+ if (tryPort !== Number(port)) {
83
+ updateEnvPort(tryPort);
84
+ console.log(`Updated .env.${env} with PORT=${tryPort}`);
85
+ }
86
+ });
87
+ listener.on("error", async (err) => {
88
+ if (err.code === "EADDRINUSE") {
89
+ const nextPort = await askPort(tryPort);
90
+ startServer(nextPort);
91
+ } else {
92
+ console.error(err);
93
+ process.exit(1);
94
+ }
95
+ });
96
+ }
97
+
98
+ startServer(Number(port));
@@ -7,13 +7,17 @@
7
7
  "start": "node index.js",
8
8
  "dev": "nodemon index.js"
9
9
  },
10
+ "nodemonConfig": {
11
+ "watch": ["."],
12
+ "ext": "js,mjs,cjs",
13
+ "ignore": ["node_modules/", "package.json", "package-lock.json", ".4bnode/"]
14
+ },
10
15
  "dependencies": {
11
- "express": "^4.19.2",
12
- "dotenv": "^16.4.5",
13
- "body-parser": "^1.20.2",
14
- "cors": "^2.8.5"
16
+ "express": "^5.2.1",
17
+ "dotenv": "^17.3.1",
18
+ "cors": "^2.8.6"
15
19
  },
16
20
  "devDependencies": {
17
- "nodemon": "^3.1.3"
21
+ "nodemon": "^3.1.14"
18
22
  }
19
23
  }
@@ -1,90 +1,292 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Welcome to 4Brains Node App</title>
7
- <style>
8
- body {
9
- margin: 0;
10
- font-family: "Courier New", Courier, monospace;
11
- background-color: #121212;
12
- color: #ffffff;
13
- display: flex;
14
- justify-content: center;
15
- align-items: center;
16
- height: 100vh;
17
- flex-direction: column;
18
- }
19
- .container {
20
- text-align: center;
21
- background: #1e1e1e;
22
- padding: 2rem 3rem;
23
- border-radius: 12px;
24
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
25
- margin-bottom: 2rem;
26
- }
27
- h1 {
28
- font-size: 2.5rem;
29
- margin-bottom: 1rem;
30
- }
31
- p {
32
- font-size: 1.2rem;
33
- margin-bottom: 2rem;
34
- color: #bbbbbb;
35
- }
36
- a {
37
- color: #ffffff;
38
- text-decoration: none;
39
- background-color: #1e90ff;
40
- padding: 0.5rem 1.5rem;
41
- border-radius: 4px;
42
- transition: background-color 0.3s, transform 0.3s;
43
- }
44
- a:hover {
45
- background-color: #0a74da;
46
- transform: scale(1.05);
47
- }
48
- .console {
49
- font-family: "Courier New", Courier, monospace;
50
- background: #000000;
51
- color: #33ff33;
52
- padding: 1rem 1rem 2rem 1rem;
53
- border-radius: 8px;
54
- margin-bottom: 1.5rem;
55
- text-align: center;
56
- line-height: 1.5;
57
- white-space: preserve-breaks;
58
- }
59
- .footer {
60
- text-align: center;
61
- color: #bbbbbb;
62
- font-size: 0.9rem;
63
- }
64
- .footer img {
65
- width: 200px;
66
- margin-bottom: 0.5rem;
67
- }
68
- </style>
69
- </head>
70
- <body>
71
- <div class="container">
72
- <div class="console">
73
- /----------------------------------\ <br />
74
- | 4Brains Node Generator | <br />
75
- \----------------------------------/
76
- </div>
77
- <h1>Welcome to 4Brains Node App</h1>
78
- <p>Your Node.js app is up and running!</p>
79
- <a
80
- href="https://github.com/pawan-4brains/4brains-node-generator"
81
- target="_blank"
82
- >Learn More</a
83
- >
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>4bnode App</title>
7
+ <style>
8
+ * { margin: 0; padding: 0; box-sizing: border-box; }
9
+
10
+ @font-face { font-family: "Noto Sans"; src: url("/_dev/assets/fonts/NotoSans-Light.woff2") format("woff2"); font-weight: 300; font-style: normal; font-display: swap; }
11
+ @font-face { font-family: "Noto Sans"; src: url("/_dev/assets/fonts/NotoSans-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
12
+ @font-face { font-family: "Noto Sans"; src: url("/_dev/assets/fonts/NotoSans-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
13
+ @font-face { font-family: "Noto Sans"; src: url("/_dev/assets/fonts/NotoSans-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
14
+ @font-face { font-family: "Noto Sans"; src: url("/_dev/assets/fonts/NotoSans-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
15
+
16
+ body {
17
+ font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
18
+ background: #0a0b10;
19
+ color: #e2e8f0;
20
+ min-height: 100vh;
21
+ display: flex;
22
+ align-items: center;
23
+ justify-content: center;
24
+ overflow: hidden;
25
+ }
26
+
27
+ .scene {
28
+ position: fixed;
29
+ inset: 0;
30
+ z-index: 0;
31
+ }
32
+
33
+ /* Animated grid floor */
34
+ .grid {
35
+ position: absolute;
36
+ bottom: 0;
37
+ left: 50%;
38
+ transform: translateX(-50%) perspective(600px) rotateX(55deg);
39
+ width: 200%;
40
+ height: 70vh;
41
+ background-image:
42
+ linear-gradient(rgba(0,114,255,0.08) 1px, transparent 1px),
43
+ linear-gradient(90deg, rgba(0,114,255,0.08) 1px, transparent 1px);
44
+ background-size: 60px 60px;
45
+ animation: gridScroll 12s linear infinite;
46
+ mask-image: linear-gradient(to top, rgba(0,0,0,0.4) 0%, transparent 80%);
47
+ -webkit-mask-image: linear-gradient(to top, rgba(0,0,0,0.4) 0%, transparent 80%);
48
+ }
49
+
50
+ @keyframes gridScroll {
51
+ 0% { background-position: 0 0; }
52
+ 100% { background-position: 0 60px; }
53
+ }
54
+
55
+ /* Floating orbs */
56
+ .orb {
57
+ position: absolute;
58
+ border-radius: 50%;
59
+ filter: blur(80px);
60
+ opacity: 0.35;
61
+ animation: float 8s ease-in-out infinite;
62
+ }
63
+ .orb-1 {
64
+ width: 400px; height: 400px;
65
+ background: radial-gradient(circle, #0072ff, transparent 70%);
66
+ top: 10%; left: 15%;
67
+ animation-delay: 0s;
68
+ }
69
+ .orb-2 {
70
+ width: 350px; height: 350px;
71
+ background: radial-gradient(circle, #7b2ff7, transparent 70%);
72
+ top: 30%; right: 10%;
73
+ animation-delay: -3s;
74
+ animation-duration: 10s;
75
+ }
76
+ .orb-3 {
77
+ width: 300px; height: 300px;
78
+ background: radial-gradient(circle, #00c6ff, transparent 70%);
79
+ bottom: 15%; left: 40%;
80
+ animation-delay: -5s;
81
+ animation-duration: 12s;
82
+ }
83
+
84
+ @keyframes float {
85
+ 0%, 100% { transform: translate(0, 0) scale(1); }
86
+ 33% { transform: translate(30px, -20px) scale(1.05); }
87
+ 66% { transform: translate(-20px, 15px) scale(0.95); }
88
+ }
89
+
90
+ /* Content */
91
+ .container {
92
+ position: relative;
93
+ z-index: 1;
94
+ text-align: center;
95
+ padding: 40px;
96
+ animation: fadeUp 1s ease-out;
97
+ }
98
+
99
+ @keyframes fadeUp {
100
+ from { opacity: 0; transform: translateY(30px); }
101
+ to { opacity: 1; transform: translateY(0); }
102
+ }
103
+
104
+ /* Animated node SVG */
105
+ .node-graphic {
106
+ width: 120px;
107
+ height: 120px;
108
+ margin: 0 auto 32px;
109
+ }
110
+
111
+ .node-ring {
112
+ fill: none;
113
+ stroke: url(#ringGrad);
114
+ stroke-width: 1.5;
115
+ stroke-dasharray: 8 6;
116
+ transform-origin: 60px 60px;
117
+ animation: spin 20s linear infinite;
118
+ }
119
+ .node-ring-2 {
120
+ animation: spin 15s linear infinite reverse;
121
+ stroke-dasharray: 12 8;
122
+ }
123
+ .node-ring-3 {
124
+ animation: spin 25s linear infinite;
125
+ stroke-dasharray: 4 10;
126
+ }
127
+
128
+ @keyframes spin {
129
+ to { transform: rotate(360deg); }
130
+ }
131
+
132
+ .node-dot {
133
+ fill: #0072ff;
134
+ animation: pulse 2s ease-in-out infinite;
135
+ }
136
+ .node-dot:nth-child(2) { animation-delay: 0.3s; fill: #7b2ff7; }
137
+ .node-dot:nth-child(3) { animation-delay: 0.6s; fill: #00c6ff; }
138
+ .node-dot:nth-child(4) { animation-delay: 0.9s; fill: #0072ff; }
139
+ .node-dot:nth-child(5) { animation-delay: 1.2s; fill: #7b2ff7; }
140
+ .node-dot:nth-child(6) { animation-delay: 1.5s; fill: #00c6ff; }
141
+
142
+ @keyframes pulse {
143
+ 0%, 100% { opacity: 0.5; r: 3; }
144
+ 50% { opacity: 1; r: 5; }
145
+ }
146
+
147
+ .node-line {
148
+ stroke: url(#lineGrad);
149
+ stroke-width: 0.8;
150
+ opacity: 0.4;
151
+ }
152
+
153
+ .node-center {
154
+ fill: url(#centerGrad);
155
+ filter: drop-shadow(0 0 8px rgba(0,114,255,0.4));
156
+ }
157
+
158
+ h1 {
159
+ font-size: 36px;
160
+ font-weight: 800;
161
+ letter-spacing: -0.5px;
162
+ margin-bottom: 12px;
163
+ background: linear-gradient(135deg, #ffffff 0%, #94a3b8 100%);
164
+ -webkit-background-clip: text;
165
+ -webkit-text-fill-color: transparent;
166
+ }
167
+
168
+ .tagline {
169
+ font-size: 15px;
170
+ color: #64748b;
171
+ font-weight: 400;
172
+ letter-spacing: 0.3px;
173
+ margin-bottom: 32px;
174
+ }
175
+
176
+ .status {
177
+ display: inline-flex;
178
+ align-items: center;
179
+ gap: 8px;
180
+ padding: 8px 20px;
181
+ border-radius: 100px;
182
+ background: rgba(16, 185, 129, 0.08);
183
+ border: 1px solid rgba(16, 185, 129, 0.2);
184
+ font-size: 13px;
185
+ color: #10b981;
186
+ font-weight: 500;
187
+ animation: fadeUp 1s ease-out 0.3s both;
188
+ }
189
+
190
+ .status-dot {
191
+ width: 8px;
192
+ height: 8px;
193
+ border-radius: 50%;
194
+ background: #10b981;
195
+ animation: blink 2s ease-in-out infinite;
196
+ box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
197
+ }
198
+
199
+ @keyframes blink {
200
+ 0%, 100% { opacity: 1; }
201
+ 50% { opacity: 0.4; }
202
+ }
203
+
204
+ .powered {
205
+ position: fixed;
206
+ bottom: 28px;
207
+ left: 0;
208
+ right: 0;
209
+ text-align: center;
210
+ font-size: 12px;
211
+ color: #334155;
212
+ letter-spacing: 0.3px;
213
+ animation: fadeUp 1s ease-out 0.6s both;
214
+ }
215
+ .powered a {
216
+ text-decoration: none;
217
+ }
218
+ .powered span {
219
+ font-weight: 600;
220
+ background: linear-gradient(135deg, #00c6ff, #7b2ff7);
221
+ -webkit-background-clip: text;
222
+ -webkit-text-fill-color: transparent;
223
+ transition: opacity 0.2s;
224
+ }
225
+ .powered a:hover span {
226
+ opacity: 0.75;
227
+ }
228
+ </style>
229
+ </head>
230
+ <body>
231
+
232
+ <div class="scene">
233
+ <div class="orb orb-1"></div>
234
+ <div class="orb orb-2"></div>
235
+ <div class="orb orb-3"></div>
236
+ <div class="grid"></div>
237
+ </div>
238
+
239
+ <div class="container">
240
+ <svg class="node-graphic" viewBox="0 0 120 120">
241
+ <defs>
242
+ <linearGradient id="ringGrad" x1="0%" y1="0%" x2="100%" y2="100%">
243
+ <stop offset="0%" stop-color="#0072ff" />
244
+ <stop offset="100%" stop-color="#7b2ff7" />
245
+ </linearGradient>
246
+ <linearGradient id="lineGrad" x1="0%" y1="0%" x2="100%" y2="100%">
247
+ <stop offset="0%" stop-color="#0072ff" stop-opacity="0.6" />
248
+ <stop offset="100%" stop-color="#7b2ff7" stop-opacity="0.2" />
249
+ </linearGradient>
250
+ <radialGradient id="centerGrad" cx="50%" cy="50%" r="50%">
251
+ <stop offset="0%" stop-color="#0072ff" />
252
+ <stop offset="100%" stop-color="#7b2ff7" />
253
+ </radialGradient>
254
+ </defs>
255
+
256
+ <!-- Connection lines -->
257
+ <line class="node-line" x1="60" y1="60" x2="60" y2="14" />
258
+ <line class="node-line" x1="60" y1="60" x2="100" y2="37" />
259
+ <line class="node-line" x1="60" y1="60" x2="100" y2="83" />
260
+ <line class="node-line" x1="60" y1="60" x2="60" y2="106" />
261
+ <line class="node-line" x1="60" y1="60" x2="20" y2="83" />
262
+ <line class="node-line" x1="60" y1="60" x2="20" y2="37" />
263
+
264
+ <!-- Rotating rings -->
265
+ <circle class="node-ring" cx="60" cy="60" r="50" />
266
+ <circle class="node-ring node-ring-2" cx="60" cy="60" r="38" />
267
+ <circle class="node-ring node-ring-3" cx="60" cy="60" r="26" />
268
+
269
+ <!-- Orbiting dots -->
270
+ <circle class="node-dot" cx="60" cy="14" r="4" />
271
+ <circle class="node-dot" cx="100" cy="37" r="4" />
272
+ <circle class="node-dot" cx="100" cy="83" r="4" />
273
+ <circle class="node-dot" cx="60" cy="106" r="4" />
274
+ <circle class="node-dot" cx="20" cy="83" r="4" />
275
+ <circle class="node-dot" cx="20" cy="37" r="4" />
276
+
277
+ <!-- Center node -->
278
+ <circle class="node-center" cx="60" cy="60" r="8" />
279
+ </svg>
280
+
281
+ <h1>Your app is running</h1>
282
+ <p class="tagline">Server is live and ready to accept requests</p>
283
+ <div class="status">
284
+ <span class="status-dot"></span>
285
+ All systems operational
84
286
  </div>
85
- <div class="footer">
86
- <img src="https://cdn.4brains.in/logo.png" alt="4Brains Logo" />
87
- <p>© 2023 4Brains Technologies Pvt Ltd. All rights reserved.</p>
88
- </div>
89
- </body>
287
+ </div>
288
+
289
+ <div class="powered">Powered by <a href="https://www.npmjs.com/package/4bnode" target="_blank" rel="noopener noreferrer"><span>4bnode</span></a></div>
290
+
291
+ </body>
90
292
  </html>