4bnode 4.0.3 → 4.0.5

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.
@@ -0,0 +1,29 @@
1
+ # ──────────────────────────────────────────────────
2
+ # 4Brains Node project — environment variables
3
+ #
4
+ # Copy this file:
5
+ # cp .env.example .env.development
6
+ # then fill in real values for local dev.
7
+ #
8
+ # Production values are managed in IntraApp:
9
+ # IntraApp → Deployments → <your-app> → ⋯ → Environment variables
10
+ # ──────────────────────────────────────────────────
11
+
12
+ # --- Runtime ---
13
+ NODE_ENV=development
14
+ PORT=3000
15
+
16
+ # --- Database (uncomment after `4bnode add mongo`) ---
17
+ # MONGO_URI=mongodb://127.0.0.1:27017/your-db-name
18
+
19
+ # --- Auth (uncomment after `4bnode add login`) ---
20
+ # JWT_SECRET=replace-with-a-long-random-string-min-32-chars
21
+
22
+ # --- External services (uncomment as you add them) ---
23
+ # SMTP_HOST=
24
+ # SMTP_PORT=
25
+ # SMTP_USER=
26
+ # SMTP_PASSWORD=
27
+ # TWILIO_ACCOUNT_SID=
28
+ # TWILIO_AUTH_TOKEN=
29
+ # MICROSOFT_CLIENT_ID=
@@ -0,0 +1,65 @@
1
+ # node-skeleton-app
2
+
3
+ Express 5 + Dotenv + CORS app, scaffolded by [4bnode](https://github.com/pawan-4brains/4bnode).
4
+
5
+ ## Bootstrap (new machine / fresh clone)
6
+
7
+ ### 1. Install dependencies
8
+
9
+ ```bash
10
+ npm install
11
+ ```
12
+
13
+ ### 2. Get the env file
14
+
15
+ This project keeps secrets out of git. Pick the source that applies:
16
+
17
+ | You are | Get values from |
18
+ |---|---|
19
+ | Setting up local dev | Bitwarden item: **`4bnode-<project-name> · .env.development`** |
20
+ | Bringing up a new prod deployment | IntraApp → Deployments → `<deployment>` → Environment variables |
21
+ | You have neither | Ping #dev-platform on Slack with the project name |
22
+
23
+ Once you have the values:
24
+
25
+ ```bash
26
+ cp .env.example .env.development
27
+ # then edit .env.development and fill in the real values
28
+ ```
29
+
30
+ ### 3. Run it
31
+
32
+ ```bash
33
+ npm run dev
34
+ ```
35
+
36
+ The app starts at `http://localhost:$PORT` and the dev dashboard at `http://localhost:$PORT/_dev`.
37
+
38
+ ### 4. When you add a new env variable
39
+
40
+ 1. Add it to your local `.env.development` with a real value.
41
+ 2. Add it to `.env.example` with a placeholder. Commit the change.
42
+ 3. Add the real production value in **IntraApp → Environment variables**.
43
+ 4. Update the Bitwarden item if other devs need the same value locally.
44
+
45
+ This four-step rule keeps every developer in sync without ever touching git history.
46
+
47
+ ## Project structure
48
+
49
+ ```
50
+ .
51
+ ├── index.js # Express app entry point
52
+ ├── package.json
53
+ ├── .env.example # Committed — documents required keys
54
+ ├── .env.development # Gitignored — your local values
55
+ ├── .4bnode/ # Dashboard engine & data (managed by 4bnode)
56
+ ├── public/ # Static files
57
+ └── src/
58
+ ├── db.js # MongoDB connection (after `4bnode add mongo`)
59
+ ├── models/ # Mongoose schemas
60
+ └── routes/ # API route files
61
+ ```
62
+
63
+ ## Extending with 4bnode
64
+
65
+ Run `4bnode add` inside this project to scaffold MongoDB, CRUD, login, sockets, and more. See the [4bnode README](https://github.com/pawan-4brains/4bnode) for the full feature list.
package/skeleton/index.js CHANGED
@@ -8,7 +8,8 @@ import { createInterface } from "readline";
8
8
 
9
9
  // ── Environment ─────────────────────────────────────
10
10
  const env = process.env.NODE_ENV || "development";
11
- dotenv.config({ path: `.env.${env}` });
11
+ dotenv.config({ path: `.env.${env}` }); // local dev: .env.development / .env.production
12
+ dotenv.config(); // IntraApp prod: plain .env (won't override existing)
12
13
 
13
14
  const app = express();
14
15
  const port = process.env.PORT || 3000;
@@ -86,6 +87,11 @@ async function startServer(tryPort) {
86
87
  });
87
88
  listener.on("error", async (err) => {
88
89
  if (err.code === "EADDRINUSE") {
90
+ if (!process.stdin.isTTY) {
91
+ // Running under pm2 / systemd / IntraApp — no terminal to prompt.
92
+ console.error(`Port ${tryPort} is in use and no TTY is available. Exiting.`);
93
+ process.exit(1);
94
+ }
89
95
  const nextPort = await askPort(tryPort);
90
96
  startServer(nextPort);
91
97
  } else {
@@ -1 +0,0 @@
1
- PORT=3000
@@ -1 +0,0 @@
1
- PORT=3000